heftycrow
heftycrow

Reputation: 1

Legend for scatter-line graph in ggplot2 (without colour)

very new to this so apologies if there's an obvious answer. I'm trying to add a legend to a scatter-line graph with 2 y variables; i'm aware this can be done using colour, however I ideally want to keep this black and white, and define the variables in the legend by linetype/point instead. Is there any way to do this?

ggplot(birds, aes(distance)) +geom_point(aes(y=individuals_AC)) +geom_point(aes(y=species_AC, shape=17)) +geom_line(aes(y=individuals_AC)) +geom_line(aes(y=species_AC, linetype="dashed")) + scale_shape_identity() + scale_linetype_identity() + theme_classic()

Upvotes: 0

Views: 86

Answers (1)

Jordo82
Jordo82

Reputation: 816

library(tidyverse)

#create some dummy data
df <- tibble(
  x = runif(10),
  y = runif(10),
  type = rep(c("a", "b"), 5)
)

#plot it with a different shape for each type
df %>% 
  ggplot(aes(x, y, shape = type)) + 
  geom_point()

Upvotes: 1

Related Questions