admin管理员组

文章数量:1278820

I am plotting a raster using ggplot2 with scale_fill_distiller for continuous temperature data. I would like to have the control over the limits in the legend which does not seem to work with scale_fill_distiller. The only line that works is breaks = seq(22.6, 23.9, 0.2) but it not what I need. Is there a way to use only lowest and highest value of SpatRaster with scale_fill_distiller or should I use a different one? Here is the code I use:

p <- ggplot() + geom_spatraster_rgb(data=map, maxcell = 100) p <- p + geom_spatraster(data=pred1, aes(fill = var1.pred), alpha = 0.8) p <- p + geom_sf(data=polygon,fill = "transparent", colour = "white", size = 1, linetype = "solid") p <- p + scale_fill_distiller(name = expression("T"["mean"]~(degreeC)),palette = "YlOrRd",na.value = NA, trans = "reverse",aesthetics = "fill") p <- p + theme_linedraw() p <- p + theme(legend.position = c(0.94, 0.19), legend.background = element_rect(fill = alpha("white",.75)),legend.text = element_text(size = 3, colour = "black",family="serif",margin = margin(l = 1.2)), legend.title = element_text(size = 3, colour = "black",family="serif",margin = margin(b =1)),legend.key=element_blank(),legend.key.width = unit(0.15, "cm"),legend.key.height = unit(0.15, "cm"),legend.margin =margin(r=1,l=1,t=1,b=1.5),legend.spacing.x = unit(0.01, 'cm'),legend.spacing.y = unit(0.01, 'cm'),legend.ticks = element_line(colour = "black", linewidth = 0.05), legend.ticks.length = unit(0.02, "cm")) p <- p + labs(y=NULL, x=NULL) + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0)) p <- p + theme(axis.text=element_blank(),axis.title=element_blank(),axis.ticks = element_blank(),axis.line = element_blank(),axis.ticks.length = unit(0, "pt"),) p <- p + theme(panel.grid.major= element_blank(),panel.grid.minor = element_blank(),panel.border = element_blank(),plot.background = element_blank(),panel.background = element_blank(),plot.margin = unit(c(0,0,0,0),"mm"))*

I tried other options for continuous data but with similar issue or undesired other outcomes.

本文标签: rscalefilldistiller with min and maxStack Overflow