[R-sig-Geo] geom_points adjusting size for multiplot

Sara Rivero Calle sara_erasmus at yahoo.es
Thu Mar 26 16:58:21 CET 2015


Hi, 
 I am using ggplot2 and geometric points. I am trying to create a plot with 3 different panels, one for each time period, I want the size of the points to be a function of the value in column “CB" and since there is a lot of overlapping I used the alpha=CB so that its slightly transparent. CB goes from 0-420000. I used a subset of the data frame for each time period and the problem is that each time period has a different maximum (subset 1 ranges from 200 000, subset 2 has a max of 420 000 and subset 3 about 60 000. What I have so far works but I want to have all 3 of them sharing the same legend and the size of the points be consistent for all 3 plots. How do I modify the breaks into 20 000, 50 000, 100 000, 200 000, 400 000 ?


library(maps)
library(ggplot2)
library(data frame)
library(spatstat)
library(sp)
library(map tools)

wrld <- map_data("world")
CPR<-read.csv("matchupP605.csv",header=TRUE)


subset1<-CPR[which(CPR$YearCollected>=1960 & CPR$YearCollected<1980& CPR$CB>0),]
 subset2 <-CPR[which(CPR$YearCollected>=1980 & CPR$YearCollected<2000& CPR$CB>0),]
 subset3 <-CPR[which(CPR$YearCollected>=2000 & CPR$YearCollected<2011& CPR$CB>0),]

source("http://peterhaschke.com/Code/multiplot.R") ## for the multiplot function.

	p6<-ggplot(subset1, aes(x = Longitude, y = Latitude))+ geom_point(aes(size=CB, alpha=CB), colour="red")+ coord_equal() + geom_path(data=wrld, aes(x=long, y=lat, group = group))+ xlim(-80,10) + ylim(30,65) 	+ theme_bw(base_size = 12, base_family = "Helvetica")	# alpha modifies transparency

	p7<-ggplot(subset2, aes(x = Longitude, y = Latitude))+ geom_point(aes(size=CB, alpha=CB), colour="red")+ coord_equal() + geom_path(data=wrld, aes(x=long, y=lat, group = group))+ xlim(-80,10) + ylim(30,65) + theme_bw(base_size = 12, base_family = "Helvetica")	

	p8<-ggplot(subset3, aes(x = Longitude, y = Latitude))+ geom_point(aes(size=CB, alpha=CB), colour="red")+ coord_equal() + geom_path(data=wrld, aes(x=long, y=lat, group = group))+ xlim(-80,10) + ylim(30,65)+ theme_bw(base_size = 12, base_family = "Helvetica")

multiplot(p6, p7, p8)

Thanks in advance!


More information about the R-sig-Geo mailing list