help with contour plot

26 views
Skip to first unread message

jatin.kala.jk

unread,
Dec 16, 2016, 6:02:15 AM12/16/16
to ggplot2
Hi ggplot community,
I am trying to do a contour plot of (longitude, latitude, concentration).
This is easy enough using filled.contour.
However, i am trying to do the same contour plot using ggplot, and overlaying the plot on google-map.
The script and data being read is attached.
 test_filled_contour_plot.png is what contour.filled gives me.
GF_test.png is the output from using ggplot. Something is going wrong, but i can't figure out what, and it's doing my head-in....
Any help would be greatly appreciated.
Cheers,
Jatin
ALL_HOURLY_NOX_Processed
ggmap_attempt_GF.R
test_filled_countour_plot.png
GF_test.png

Ista Zahn

unread,
Dec 16, 2016, 11:53:17 AM12/16/16
to jatin.kala.jk, ggplot2
Hi Jatin,

My basic approach would be

load("ALL_HOURLY_NOX_Processed")

data_plot <- max_conc
dimnames(data_plot) <- list(lon = lon, lat = lat)

data_plot <- reshape2::melt(data_plot, value.name = "max_conc")

ggplot(data_plot, aes(lon, lat, color = max_conc, z = max_conc)) +
stat_contour(aes(color = ..level.., fill = ..level..), geom =
"contour", bins = 10)

But here we hit a dead end, because stat_contour doesn't generate
lines that work with geom_polygon, and we need geom_polygon for fill.

ggplot(data_plot, aes(lon, lat, color = max_conc, z = max_conc)) +
stat_contour(aes(color = ..level.., fill = ..level..), geom =
"polygon", bins = 10)

is tantalizingly close, but not good enough. Making it work correctly
will be hard I'm afraid. See
https://github.com/tidyverse/ggplot2/issues/1066 and despair.

Something along the lines of

ggplot(data_plot, aes(lon, lat, z = max_conc)) +
geom_raster(aes(fill = max_conc)) +
geom_contour(bins = 10)

might be good enough.

Best,
Ista
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages