简体   繁体   中英

Set default plotting values in R

I'm trying to set default parameters for the graphical plotting of functions. However, whenever I assign a vector to col I get the error graphical parameter "col" has the wrong length .

The code I'm trying:

par(col=c("#000", "#ccc"), font.lab=2, col.axis="#404040") 

Which I hope outputs a bar plot with a colour black and light gray, whose axis labels are in bold and in a dark gray colour.

For instance, the following code (borrowed from lukeA below) produces a grayscale example, not in colour. Nor is the font in bold.

par(font.lab=2, fg="#404040", bg="#ffffff") 
# Defining palette plot colours = NOT gray scale
palette(c("paleturquoise3", "palegreen3"))

set.seed(1)

tRegion <- table(Region = sample(1:3, size = 50, replace = TRUE), 
                 Variant = sample(LETTERS[1:2], size = 50, replace = TRUE))

barplot(t(tRegion), main="Distribution of variant and region",
        xlab="Region", legend = rownames(t(tRegion)))

The output is as follows:

在此处输入图片说明

No bold font, and no colour.

Try this

par(font.lab=2, col.axis="#404040") 
palette(c("#000000", "#cccccc"))
barplot(1:2, col = 1:2, names.arg = 1:2, xlab = "1", ylab = "2")

Edit:

With regards to your comment - works for me:

par(font.lab=2, col.axis="#404040") 
palette(c("paleturquoise3", "palegreen3"))
set.seed(1)
tRegion <- table(Region = sample(1:3, size = 50, replace = TRUE), 
                 Variant = sample(LETTERS[1:2], size = 50, replace = TRUE))
barplot(t(tRegion), main="Distribution of variant and region",beside = TRUE,
        col = seq_len(ncol(tRegion)), xlab="Region", legend = rownames(t(tRegion)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM