geom_contour from ggplot2

In fact I am using ggplot2 to plot contour of sea level pressure using geom_contour. I can plot values without problem. Now I need to plot a specific value (here 1015) as bold or thicker contour than the others and wonder if you see a way to do it?
below the command I use:

syn_plot <- ggplot() +
geom_tile(data = synclas_gather_df, aes(x=x, y=y, fill=value)) +
geom_sf(data = map_bg, fill="transparent")+eom_contour2(data = synclas_gather_df, aes(x=x,y=y,z=value), binwidth = 2, color = "black") +
scale_fill_gradientn(colours = colorRamps::matlab.like2(100), name = "hPa",breaks=0:5) +
scale_colour_gradient(guide = 'none') + facet_wrap(~key, ncol = 4) +

The interval I have here is 2, so I have let's say 1010, 1012, 1014, 1016 etc. Now how to skip the 1014 and replace it with 1015?

You should be able to do this by plotting 1015 with a different lineweight, but it would be much easier to say if we could run the code.

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.

Thank you, I am not familiar with reprex and then looking a way to use it. The data I use is spatial and in netcdf format, big in general. I'll look a way to extract a sample and wonder if it could be attached?

In fact it is the raw data used which is in netcdf and then transformed as df. I'll try to see the way to extract something for the reprex?

I attempted to create a reprex example but not sure it is correct?


df <- data.frame(stringsAsFactors = FALSE)
x = c(-35, -32.5, -30, -27.5, -25, -22.5, -20,-17.5, -15, -12.5, -10, -7.5, -5, -2.5, 0)
y = c(35, 35, 35,35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35)
value = c(1024.3188583815,
1023.79053468208, 1023.43251445087, 1022.46445086705, 1021.19479768786,
1019.90079479769, 1018.68981213873, 1017.22803468208, 1015.91596820809,
1015.32861271676, 1014.61893063584, 1014.43945086705, 1014.36567919075,
1014.35433526012, 1014.26336705202)
map_bg <- ne_countries(continent = "africa", returnclass = "sf")
geom_sf(data = map_bg, fill="transparent")+
geom_contour2(data = df, aes(x=x,y=y,z=value), binwidth = 4, color = "black") +
scale_fill_gradientn(colours = colorRamps::matlab.like2(100), name = "hPa") +
scale_colour_gradient(guide = 'none') + facet_wrap(~key, ncol = 4) +
scale_x_continuous(limits = c(-9,34), expand = c(0, 0))+
scale_y_continuous(limits = c(34,29), expand = c(0,0))+
theme_bw() + theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())
Hope it shows what I am doing

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.