0

I want to highlight a subset of values in a scatter ggplot. However I get an error message and I dont know how to fix it (I am new in computational analysis) Here is the command:

ggplot(table, aes(x=soma_1.5.2.5h, y=PGC_1.5.2.5h)) +
  geom_point(shape=1, color = "gray") +
  geom_point(data = subset(table, high == TRUE), 
                    aes(x=table$soma_1.5.2.5h, y=PGC_1.5.2.5h, size = 2, color = "orange")) 

So I want to highlight dots that are "TRUE" for high. I got:

Aesthetics must be either length 1 or the same as the data (108): x, y, size, colour.

108 is the number of values that are TRUE for high. Thanks a for your help

www
  • 38,575
  • 12
  • 48
  • 84
M.B
  • 1
  • Try this: `geom_point(data = subset(table, high == TRUE), aes(x=table$soma_1.5.2.5h, y=PGC_1.5.2.5h), size = 2, color = "orange")` – A Gore Jul 17 '17 at 13:37
  • 4
    You wrote `x=table$soma_1.5.2.5h` in your second (subsetted) `aes`. Try simply `x=soma_1.5.2.5h` instead. `table` still refers to the full (original) data frame. You want to refer to the subsetted data frame. – CPak Jul 17 '17 at 13:41
  • 1
    As a general rule, _don't use `$` inside `aes`_. – Axeman Jul 17 '17 at 13:51
  • You could replace the second term with `geom_point(aes(shape=high,color=high))` and delete the last term. Add some `scale_shape` and `scale_color` terms to customise the shapes and colors. – Andrew Gustar Jul 17 '17 at 14:19
  • Thanks a lot! it worked. Also thanks for your advices – M.B Jul 18 '17 at 07:19

0 Answers0