r - Label minimum and maximum of scale fill gradient legend with text: ggplot2 -
i have plot created in ggplot2 uses scale_fill_gradientn. i'd add text @ minimum , maximum of scale legend. example, @ legend minimum display "minimum" , @ legend maximum display "maximum". there posts using discrete fills , adding labels numbers instead of text (e.g. here), unsure how use labels feature scale_fill_gradientn insert text @ min , max. @ present apt getting errors:
error in scale_labels.continuous(scale, breaks) : breaks , labels different lengths
is text label possible within ggplot2 type of scale / fill?
# example code here produces plot illustrative purposes only. # create data frame, ggplot2 documentation df <- expand.grid(x = 0:5, y = 0:5) df$z <- runif(nrow(df)) #plot ggplot(df, aes(x, y, fill = z)) + geom_raster() + scale_fill_gradientn(colours=topo.colors(7),na.value = "transparent")
for scale_fill_gradientn() should provide both arguments: breaks= , labels= same length. argument limits= extend colorbar minimum , maximum value need.
ggplot(df, aes(x, y, fill = z)) + geom_raster() + scale_fill_gradientn(colours=topo.colors(7),na.value = "transparent", breaks=c(0,0.5,1),labels=c("minimum",0.5,"maximum"), limits=c(0,1)) 
Comments
Post a Comment