about different y-axis

28 views
Skip to first unread message

lily li

unread,
Nov 29, 2015, 8:43:20 PM11/29/15
to ggp...@googlegroups.com
Hi ggplot users,

I don't know how to draw one variable reversed while the other one normal order on y-axis in ggplot?

df
month   A    B 
1           10  0.5
2           15  0.7
3           18  0.8
4           16  1
5           20  1.1
6           12  0.6

plot1= ggplot()+geom_path(data=df,aes(x=month,y=B))+
  scale_y_continuous(trans='reverse')
print(plot1)

But if I want to put only B reversed, and plot A on the same plot but in normal y-axis. how to do it? the code does not work
plot2 = ggplot()+geom_path(data=df,aes(x=month,y=B,color='b'))+
 geom_path(data=df,aes(x=month,y=A,color='a'))+scale_y_continuous(trans='reverse')+scale_color_manual(limits=c('b','a'),values=c('red','blue'))
print(plot2)
also, I want to apply the trans='reverse' only to B variable. Thanks for your help.

Roman Luštrik

unread,
Nov 30, 2015, 2:50:26 AM11/30/15
to lily li, ggp...@googlegroups.com
Hi,

for color, you should probably use a non-character, preferably a value. If you don't have column 'b', you could specify color outside the aes() call.
Have you tried using `rev(B)`?

Cheers,
Roman 

--
--
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.



--
In God we trust, all others bring data.
Reply all
Reply to author
Forward
0 new messages