1

I'm trying to map a continuous variable on my plot. Perhaps by means of color gradient. But I have not succeeded yet. Any suggestion for adding "gamma" to my plot? I would like also to indicate location of each category (2 levels) on the plot, is that feasible on a single plot?

 plot_2 <- ggplot(data=states_2)+  ggtitle("TBD ")+
 xlab("q")+ylab("r")+ geom_point(aes(x=Q , y= Cor, color=metric))+geom_smooth (aes(x=Q, y=Cor, 
color=metric,group=(metric)),
 method="lm", se=FALSE)

   Cor  metric  K     Q  Category     gamma
  0.33  APD    2s   0.4mu   64spp   -0.25282382
  0.23  APD    2s   0.4mu   64spp   -0.653438937
  0.21  APD    2s   0.4mu   64spp   0.799639202
  0.14  APD    2s   0.4mu   64spp   1.039215902
  0.37  APD    2s   0.4mu   64spp   0.207669854
Mike Wise
  • 22,131
  • 8
  • 81
  • 104
Jack
  • 165
  • 2
  • 12
  • 1
    Without the output from `dput(states_2)` potential respondents will be doing guesswork on your rather ambiguous problem description. – IRTFM Nov 07 '15 at 01:24
  • That's the first five rows of states_2 dataset. @BondedDust – Jack Nov 07 '15 at 01:37
  • 2
    @Jack: You have asked a number of `r` questions that can be improved by learning more about how to create a minimal, reproducible example. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – bdemarest Nov 07 '15 at 03:59

1 Answers1

1

Well, as the comments indicated, you did not give us a lot to go on (you really need to work on your question posing as bdemarest mentioned). So I created some similar fake data (as far as I could figure it out) and did this. The easiest way to bring gamma into this picture is by adjusting the size of the points.

# fake some data into states_2
#
# Cor  metric  K     Q  Category     gamma
# 0.33  APD    2s   0.4mu   64spp   -0.25282382
# 0.23  APD    2s   0.4mu   64spp   -0.653438937
# 0.21  APD    2s   0.4mu   64spp   0.799639202
# 0.14  APD    2s   0.4mu   64spp   1.039215902
# 0.37  APD    2s   0.4mu   64spp   0.207669854
#
n <- 100
cor <- rnorm(n,0.25)
me <- sample(c("APD","APE","APF"),n,replace=T)
kk <- sample(c("2s","3t","4u"),n,replace=T)
qq <- sample(c("0.2mu","0.3mu","0.4mu","0.5mu","0.6mu"),n,replace=T)
ca <- sample(c("64spp","80spp"),n,replace=T)
ga <- rnorm(n,0.5,2)
states_2 <- data.frame(Cor=cor,metric=me,K=kk,Q=qq,Category=ca,gamma=ga)

# plot it
plot_2 <- ggplot(data=states_2)+  
  ggtitle("TBD ")+xlab("q")+ylab("cor")+ 
  geom_point(aes(x=Q , y= Cor, color=metric, size=gamma, alpha=0.5))+
  geom_smooth( aes(x=Q,y=Cor, color=metric,group=(metric)), method="lm",se=FALSE)+
  guides(alpha=F)

print(plot_2)

yields: enter image description here

Mike Wise
  • 22,131
  • 8
  • 81
  • 104