Hi, I am looking for a way to plot bar on a map instead of the standard points. I have been using ggplot2 and maps libraries. The points are added with the function geom_point. I know that there is a function geom_bar but I can't figure out how to use it. Thank you for your help, Simon ### R-code library(ggplot2) library(maps) measurements <- read.csv("all_podo.count.csv", header=T) allworld <- map_data("world") pdf("map.pdf") ggplot(measurements, aes(long, lat)) + geom_polygon(data = allworld, aes(x = long, y = lat, group = group), colour = "grey70", fill = "grey70") + geom_point(aes(size = ref)) + opts(axis.title.x = theme_blank(), axis.title.y = theme_blank()) + geom_bar(aes(y = normcount)) dev.off() ### -- View this message in context: http://r.789695.n4.nabble.com/Plotting-bar-graph-over-a-geographical-map-tp4346925p4346925.html Sent from the R help mailing list archive at Nabble.com.
If you are willing to use base graphics instead of ggplot2 graphs, then look at the subplot function in the TeachingDemos package. One of the examples there shows adding multiple small bar graphs to a map. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of sjlabrie > Sent: Tuesday, January 31, 2012 9:53 PM > To: r-help at r-project.org > Subject: [R] Plotting bar graph over a geographical map > > Hi, > > I am looking for a way to plot bar on a map instead of the standard > points. > I have been using ggplot2 and maps libraries. > The points are added with the function geom_point. I know that there is > a > function > geom_bar but I can't figure out how to use it. > > Thank you for your help, > > Simon > > ### R-code > library(ggplot2) > library(maps) > > measurements <- read.csv("all_podo.count.csv", header=T) > allworld <- map_data("world") > > pdf("map.pdf") > ggplot(measurements, aes(long, lat)) + > geom_polygon(data = allworld, aes(x = long, y = lat, group = group), > colour = "grey70", fill = "grey70") + > geom_point(aes(size = ref)) + > opts(axis.title.x = theme_blank(), > axis.title.y = theme_blank()) + > geom_bar(aes(y = normcount)) > dev.off() > ### > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Plotting- > bar-graph-over-a-geographical-map-tp4346925p4346925.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Simon, You might want to try sending a small reproducible example (https://github.com/hadley/devtools/wiki/Reproducibility) to the ggplot2 mailing list. Hadley On Tue, Jan 31, 2012 at 10:53 PM, sjlabrie <sjlabrie at mit.edu> wrote:> Hi, > > I am looking for a way to plot bar on a map instead of the standard points. > I have been using ggplot2 and maps libraries. > The points are added with the function geom_point. I know that there is a > function > geom_bar but I can't figure out how to use it. > > Thank you for your help, > > Simon > > ### R-code > library(ggplot2) > library(maps) > > measurements <- read.csv("all_podo.count.csv", header=T) > allworld <- map_data("world") > > pdf("map.pdf") > ggplot(measurements, aes(long, lat)) + > ?geom_polygon(data = allworld, aes(x = long, y = lat, group = group), > ?colour = "grey70", fill = "grey70") + > ?geom_point(aes(size = ref)) + > ?opts(axis.title.x = theme_blank(), > ?axis.title.y = theme_blank()) + > ?geom_bar(aes(y = normcount)) > dev.off() > ### > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Plotting-bar-graph-over-a-geographical-map-tp4346925p4346925.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
You could try the library mapplots, see example below: http://r.789695.n4.nabble.com/file/n4635091/xy.png -- View this message in context: http://r.789695.n4.nabble.com/Plotting-bar-graph-over-a-geographical-map-tp4346925p4635091.html Sent from the R help mailing list archive at Nabble.com.