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
On Aug 4, 2010, at 7:52 AM, Dieter Vanderelst wrote:> 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 >Happens on a Mac, too (OSX 10.5.8, R 2.11.1, ggplot2 0.8.8 ) If you just want to make the dots go away, you can use: qplot(DT$N,DT$D,fill=DT$C, geom = "bar", stat="identity",position="dodge") But you should probably also report it to Hadley.> version info: > Windows xp 64 > R version 2.11.1 (64 bit) > ggplot2 version 0.8.8-- David Winsemius, MD West Hartford, CT
The reason you see the exra markers is that the first part of the command "qplot(DT$N,DT$D,fill=factor(DT$C))" already plots the individual points. You didn't see it with "geom_bar(stat = "identity")" simply because the stacked bars made the previous layer invisible. To see this you can use the ggplot function to reproduce your graph (with the points): p<-ggplot(data=DT,aes(x=N,y=D))+geom_point()+geom_bar(stat="identity",aes(fill=factor(C)),position="dodge") print(p) It then becomes obvious that once you omit the geom_point(), the points are gone. This is IMO a feature of the ggplot2 system, not necessarily a bug. -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-barplot-extra-markers-in-graph-tp2313337p2313426.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- ggplot2: ordering categorial data
- barplot that displays sums of values of 2 y colums grouped by different variables
- barplot that displays sums of values of 2 y colums grouped by different variables
- simple plot in ggplot2, wrong error bars
- ggplot2 plotting errorbars.