Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Continuous x aesthetic -- did you forget aes(group=...) mean?

Tags:

r

ggplot2

Scatterplot<-ggplot(
     diamonds[sample(nrow(diamonds), 1000), ],
     aes(carat, price, colour=clarity)
  )+
  geom_point(position="jitter", alpha=0.6)+
  facet_grid(~cut) + 
  scale_x_continuous(breaks=seq(0, 5, 1)) + 
  geom_boxplot(alpha=0, colour="black") +  
  scale_color_brewer(palette = "Set1")
  plot(Scatterplot)

I cannot find any clue about this warning. Anyone knows? Please check the picture:

output

like image 730
Zakk Yang Avatar asked Jul 05 '18 11:07

Zakk Yang


2 Answers

You can get around it with adding group = 1:

Scatterplot<-ggplot(
  diamonds[sample(nrow(diamonds), 1000), ],
  aes(carat, price, colour=clarity, group = 1)
)+
  geom_point(position="jitter", alpha=0.6)+
  facet_grid(~cut) + 
  scale_x_continuous(breaks=seq(0, 5, 1)) + 
  geom_boxplot(alpha=0, colour="black") +  
  scale_color_brewer(palette = "Set1")
plot(Scatterplot)

This removes the error. However, I did not check if your overall approach to this plot makes sense (see comments).

Regarding why group = 1 is necessary: I would recommend this chapter in R for Data Science.

like image 92
JBGruber Avatar answered Nov 07 '22 07:11

JBGruber


This happened to me because the x column wasn't character (it was numeric).

Simply mutate to character i.e.

mutate(myvariable = as.character(myvariable))
like image 30
stevec Avatar answered Nov 07 '22 07:11

stevec