I generate the legend in my ggplot2 plot with
scale_colour_discrete(name=textCF)
I like that i can see which colour belongs to which value, but it consumes to much space in the plot.
I tried also the scale_colour_gradientn
scheme, but this is so condensed, that i can not distiguish the values anymore. If i could only change the width of this colourbar.
scale_colour_gradientn(name=textCF,colours = rainbow(nrow(mydf), start=2/6), breaks=round(mydf$CF)) +
How can I improve the lookout?
The size of a colourbar can be controlled with the barwidth
and barheight
parameters.
Start with a reproducible example to see the effects:
ggplot(mtcars, aes(x=wt, y=mpg, colour=qsec)) +
geom_point() +
scale_colour_gradient() +
theme(legend.position = "bottom")
I'm using scale_colour_gradient
, but this works in general.
You control aspects of the guide with the guide
argument to a scale. See the help on guide_colourbar
for all the parameters that you can set.
ggplot(mtcars, aes(x=wt, y=mpg, colour=qsec)) +
geom_point() +
scale_colour_gradient(guide = guide_colourbar(barwidth=20, barheight=2)) +
theme(legend.position = "bottom")
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.