plotbiomes
plotbiomes copied to clipboard
Customisation of the axis - precipitation from cm to mm
hi @valentinitnelav Thanks for your pkg. Is there any way to customize the axis (change the labels of the axis, or the units)? For instance, I'm interested in plot the precipitation axis in mm not in cm. Is there any way to do it? I tried this, but it does not work
library(scales)
trans_mm = scales::trans_new("mm", \(x) x*10, \(x) x/10) # Custom transformation
whittaker_base_plot() + scale_y_continuous(trans = trans_mm)
I got the message:
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Any advice? Thanks
Hi @ajpelu , what about this example below?
The main idea is to first apply the transformation to the data and then use it to plot:
library(plotbiomes)
library(ggplot2)
data(Whittaker_biomes)
# Transform cm to mm in data (or whatever transformation you may have), then do the custom plotting
Whittaker_biomes$precp_mm <- Whittaker_biomes$precp_cm * 10
plot_1 <- ggplot() +
# add biome polygons
geom_polygon(data = Whittaker_biomes,
aes(x = temp_c,
y = precp_mm,
fill = biome),
# adjust polygon borders
colour = "gray98",
size = 1) +
# fill the polygons with predefined colors
scale_fill_manual(name = "Whittaker biomes",
breaks = names(Ricklefs_colors),
labels = names(Ricklefs_colors),
values = Ricklefs_colors) +
scale_x_continuous(expression("Temperature " ( degree*C))) +
scale_y_continuous('Precipitation (mm)') +
theme_bw()
plot_1
Ok, Thanks @valentinitnelav. It works.