Question

I want to draw a scatterplot with two kinds of plots first points represent averages with sd error bars

sou <- data.frame (Source=c("Copepods","Macroalgae","MPB"),md13C=rnorm(3,-18,5),sd13C=rnorm(3,5,2),md15N=rnorm(3,3,2),sd15N=rnorm(3,0.20,0.2))

require(ggplot2)

p <- ggplot(sou,aes(x=md13C, y=md15N))  
p <- p + geom_point(aes(shape=Source),
                    fill = "black",size=4,)+scale_shape_manual(values=c(21,22,23))

p <- p + geom_errorbarh(aes(xmin = md13C-sd13C,xmax = md13C+sd13C),height=0)
p <- p + geom_errorbar(aes(ymin = md15N-sd15N,ymax = md15N+sd15N),width=0)+theme_bw()
p

this graph have filled points with shapes I selected, now I will add the second set of points

con <- data.frame(FeedingGroup=rep(c("deposivore", "omnivore","ectosymbionts","deposit feeder",
                                        "scavenger","predator","filter feeder","predator/scavenger"),each=6),
                 Site=rep(c("Creek","Faro","Isla"),each=16),
                 d13C=rnorm(48,-18,5),d15N=rnorm(48,5,5))


p <-p +theme(legend.justification=c(0,1), legend.position=c(0,1),legend.title=element_blank())
brk <- c(unique(as.character(sou$Source)),unique(as.character(con$FeedingGroup)))
p + geom_point(data=con, aes(x=d13C, y=d15N,color=Site,shape=FeedingGroup)) + scale_shape_manual(breaks=brk,values=c(21,22,23,0,1,2,5,6,7,9,10,11,3,4,8,12,13))+guides(colour=FALSE)

the problem is that the shapes (symbols) assigned previously to the first group change, and I need the filled symbols for first group of points and hollow symbols for the second group.

And there is another problem: the unfilled symbols appears with concentric shapes!

Thanks!

Was it helpful?

Solution

In the description of ?discrete_scale, you will find the following for the breaks argument: "This parameter does not affect in any way how the data is scaled - it only affects the appearance of the legend." If you read the next line, it says that limits is "A character vector specifying the data range for the scale. and the default order of their display in guides." So you want to use limits instead of breaks:

scale_shape_manual(limits=brk, values=c(21,22,23,0,1,2,5,6,7,9,10,11,3,4,8,12,13))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top