Olivia
unread,Jul 5, 2013, 7:47:16 AM7/5/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggp...@googlegroups.com
Hi there,
I have searched the group and forums, but apologies if this has been addressed previously. My problem is that when I have a legend for geom_point size, colours
elsewhere in the plot leak into the legend. However this is only visible
intermittently (generally not when the plot is first drawn, but occurs
both in R studio and R, and inescapably when I write the plot to a pdf
or jpeg). Please let me know if further information is required. An example of the problem is attached ("as in pdf version"), while "as in r studio" shows how it is first rendered. The colour of the leak depends on the colour specified
elsewhere in the plot.
#Some made up data:
repFrame <- data.frame(A= 1:20, B= rnorm(1:20), grades= rnorm(1:20),groupNum = rep(c("First group", "Second group"),each=10), class = rep(c("Class A", "Class B","Class C","Class D","Class E"),each=4))
testPlot <- ggplot(repFrame, aes(x=A, y = B))+
geom_point(alpha=0.7, aes(size=groupNum,colour=grades))+
geom_smooth(colour="orange")+
geom_density2d(colour="pink",alpha=0.3)+
theme_bw()
testPlot #ends up with pink lines across the back of the legend for size
testPlot2 <- ggplot(repFrame, aes(x=A, y = B))+
geom_point(alpha=0.7, aes(size=groupNum,colour=grades))+
geom_smooth(colour="orange")+
geom_density2d(colour="forestgreen",alpha=0.3)+
theme_bw()
testPlot2 #ends up with forestgreen lines across the legend for size.
# I thought the addition of the code below might fix the problem, but no.
theme_bw()+
theme(legend.key=element_rect(fill="white"))+
theme(legend.background=element_rect(fill="white"))
Kind regards,
Olivia
MSc candidate