[R] ggplot2 barplot: extra markers in graph

David Winsemius dwinsemius at comcast.net
Wed Aug 4 14:20:05 CEST 2010


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



More information about the R-help mailing list