I tried to smaller the font size of the x-axis in the barplot, using cex.lab. However, there are no changes, regardless of how I play with the numbers. Hence, I am wondering what has gone wrong in my code, as shown below.
car$Brand <- factor(car$Brand) %>% fct_infreq()
plot(carl$Brand, las=2, col= "dark blue", ylim=c(0,35), cex.lab=0.2)
Additionally, I would like to ask how to fade the color from dark color to light color (from dark blue to light blue) as the data value are getting smaller
Many thanks
CodePudding user response:
You must set both cex
and cex.axis
to change the axis labels sizes.
As for the colors, colorRampPalette
returns an interpolating function between two limits.
set.seed(2022)
car <- data.frame(
Brand = sample(LETTERS[10:1], 1e3, TRUE, prob = (1:10)/10)
)
car$Brand <- factor(car$Brand) |> forcats::fct_infreq()
ncolors <- length(unique(car$Brand))
fcolors <- colorRampPalette(c("dark blue", "light blue"))
fcolors(ncolors)
#> [1] "#00008B" "#131895" "#26309F" "#3948A9" "#4C60B3" "#6078BD" "#7390C7"
#> [8] "#86A7D1" "#99C0DB" "#ADD8E6"
plot(car$Brand, las=2,
col= fcolors(ncolors),
cex = 0.5, cex.axis = 1)