[R] ggplot2 barplot: extra markers in graph

Dieter Vanderelst dieter_vanderelst at emailengine.org
Wed Aug 4 13:52:47 CEST 2010


Dear List,

(self-contained example + version info at the bottom)

I'm having trouble producing a barplot using the functions in ggplot2. When I use the position="dodge" option, the bars are plotted  but also a number of spurious markers. More specifically, a number of black dots are plotted in the graph that should not be there. This behaviour is not seen when calling the same functions without the position="dodge".

Can someone shed some light on this? How can I avoid this?

#self-contained example:
library(ggplot2)
D<-runif(30)
N<-rep(c(1:10),3)
C<-rep(c(1:3),10)
DT<-data.frame(D=D,N=N,C=C)
#works ok
qplot(DT$N,DT$D,fill=factor(DT$C))+  geom_bar(stat = "identity")
#in the resulting plot, a number of black markers are added that should not be there
qplot(DT$N,DT$D,fill=factor(DT$C))+  geom_bar(stat = "identity", position="dodge")
#end of example

version info:
Windows xp 64
R version 2.11.1 (64 bit)
ggplot2 version 0.8.8



More information about the R-help mailing list