r - Using same alpha/size scale for 2 different plots with ggplot -


i have 2 data frames use make 2 scatter plots. use 1 column set alpha , size of markers , need scaling in second plot identical first. problem while values in plot range 0 1, in plot b range 0 0.5 (the scale in b should 0 1)...

quick example:

x=seq(from=1, to=10, by=1) y=seq(from=1, to=10, by=1) markera=sample(0:100,10, replace=t)/100 markerb=sample(0:50,10, replace=t)/100 dfa=data.frame(x,y,markera) dfb=data.frame(x,y,markerb) a<- ggplot(dfa,aes(x=x, y=y)) <- + geom_point(aes(alpha=dfa$markera, size=dfa$markera)) b<- ggplot(dfb,aes(x=x, y=y)) b <- b + geom_point(aes(alpha=dfb$markerb, size=dfb$markerb)) b 

plot a plot b

i think there should easy way can't seem find it...

just add scale_size , scale_alpha plots.
ggplot2, remember not use $variable in aes

here example:

enter image description here

a = ggplot(dfa,aes(x=x, y=y)) +  geom_point(aes(alpha=markera, size=markera)) +  scale_size(limits = c(0,1)) +  scale_alpha(limits = c(0,1))  b = ggplot(dfb,aes(x=x, y=y)) +  geom_point(aes(alpha=markerb, size=markerb)) +  scale_size(limits = c(0,1)) +  scale_alpha(limits = c(0,1))  grid.arrange(a,b) 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -