mtleis
mtleis

Reputation: 732

Change shape and color of geom points in ggplot2

Here is the issue, the following code is changing the color of the data points but not the shape. What is wrong?

g <- ggplot(mydata, aes(var1, var2)
g <- g + geom_point(aes(shape=var3, color=var3), shape=1)
g <- g + facet_grid(.~var4)
g <- g + theme(legend.position="bottom") + guides(colour = guide_legend(ncol = 1))

Upvotes: 1

Views: 1725

Answers (1)

pogibas
pogibas

Reputation: 28379

Your code is almost correct. Why do you have two shapes?
Replace

geom_point(aes(shape=var3, color=var3), shape=1)

With

geom_point(aes(shape=var3, color=var3)

And this is how I would write it:

library(ggplot2)
ggplot(mydata, aes(var1, var2) +
    geom_point(aes(shape = var3, color = var3)) +
    facet_grid(. ~ var4) +
    theme(legend.position = "bottom") + 
    guides(colour = guide_legend(ncol = 1))

Upvotes: 2

Related Questions