I need to add IPCC(-style) stippling to a global map as in this post. However I would like to use one of the functions of ggplot2
for doing so.
Here an example of data and plot:
df=read.csv("/home/my_folder/test.csv")
library(ggplot2)
library(metR)
plot_df = ggplot() +
geom_contour_fill(data=df, aes(x=V1, y=V2, z = value)) +
scale_fill_steps2(name = "", low = "#0571b0", mid = '#ffffbf', high = '#ca0020')
print(plot_df)
How can I add IPCC stippling to this image?
I tried using geom_point()
but the stippling are too large and mask the background colors.
Thanks
Edit
Following @Allan answer I am indeed able to add stippling as follows:
library(ggplot2)
library(ggpattern)
df=read.csv("~/...../test.csv")
df_stippl=df[c(10:47, 100:250, 500:510, 707:1000, 1508:1699, 2500:2600, 2680:2690, 3400:4300),]
plot_df = ggplot() +
geom_contour_fill(data=df, aes(x=V1, y=V2, z = value)) +
stat_contour_fill(data=df_stippl, aes(x=V1, y=V2, z = value), geom = "polygon_pattern",
pattern_fill = "black", pattern_size = 0,
pattern = "crosshatch", pattern_spacing = 0.02,
pattern_angle = 45, pattern_density = 0.1) +
scale_fill_steps2(name = "", low = "#0571b0", mid = '#ffffbf', high = '#ca0020')
print(plot_df)
However, when I save the figure in pdf:
pdf('~/...../figure.pdf', width = 10, height = 6.6)
print(plot_df)
dev.off()
I get full stippling all over the globe and not only in the areas of df_stippl
.
You could do this a couple of ways. Perhaps the easiest is to get the centre points of a hexagonal grid covering your data and draw with
geom_point
If you want the dots to have a different density, you can change
xbins
An alternative is to filter out some of the rows of your data frame and plot the points there:
Compare all of these to just plotting the points:
Edit
If you want cross-hatching you can do:
To save your plot as pdf, you will need to use
cairo_pdf
:figure.pdf