1

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))
1
  • You have 2 times the argument shape once within aes() and once outside.Remove the one outside... Please also provide a reproducible example for any question here. Commented Sep 7, 2017 at 20:20

1 Answer 1

2

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.