1

Is there an equivalent of scale_color_manual() that would allow me to manually adjust a geom_point pointsize? I have several factors in my dataset, and one of them I would like to plot as a small point while the rest I'd like to set to a larger size.

On request, a reproducible dataset:

frame <- c(1:50)
x <- runif(50, min=0, max=500)
y <- runif(50, min=0, max=500)
behaviorsmini <- c("NA", "B", "L", "C", "E")
behaviors <- sample(behaviorsmini, size=50, replace=TRUE)
df <- as.data.frame(cbind(frame, x, y, behaviors))

ggplot(df, aes(x=as.numeric(x), y=as.numeric(y), color=behaviors, size=behaviors))+
  geom_point()+
  theme_classic()

Within the 'behaviors' group, I'd like to set the NA to some small size, and the rest of the behaviors to a large size. Right now the size argument is just assigning pointsizes without control. Thanks!

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 17 '23 at 14:40
  • You can use `scale_size_manual`, with `aes(size = (factor_variable == small_factor_value))` – Andrew Gustar Jul 17 '23 at 14:48
  • `df <- data.frame(frame, x, y, behaviors)` might be more helpful here; cbind coerces the various columns to be the same type. – Jon Spring Jul 17 '23 at 16:04

1 Answers1

0

From Andrew's answer, and also from this answer:

ggplot(df, aes(x=as.numeric(x), y=as.numeric(y), color=behaviors, size=behaviors))+
  geom_point()+
  scale_size_manual(values=c(5, 5, 5, 5, 1))+
  theme_classic()