1

I want to connect these points with lines to show reaction norms of the two species within different habitats: enter image description here

However when I use geom_line it doesn't quite show how I want it: enter image description here

This is the data frame that I'm working with: enter image description here

  • 2
    Please post your data and code as copy/pasteable text, not as pictures. We can't debug solutions on pictures. – Gregor Thomas Oct 06 '22 at 15:35
  • 3
    The general answer is that you need to specify a `group` aesthetic, with one unique value for each line. – Gregor Thomas Oct 06 '22 at 15:35
  • 2
    Welcome to SO, PeterMcGregor! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Oct 06 '22 at 15:38

1 Answers1

1
df <- data.frame(hab = c(rep('edge', 3), rep('forest', 3)), 
                 taxa = c('N. orbicollis', 
                              'N. sayi', 
                              'N. tomentos', 
                          'N. orbicollis', 
                          'N. sayi', 
                          'N. tomentos'), 
                 avg_abun = c(0.81, 0.16, 0.83, 0.89, 0.25, 1.64), 
                 sd_abun = c(1.37, 0.37, 1.41, 1.01, 0.52, 1.78))
                 
                 

library(tidyverse)

ggplot(df, 
       aes(x = hab, 
           y = avg_abun, 
           color = taxa, 
           group = taxa)) +
  geom_point() +
  geom_line()

sample

Susan Switzer
  • 1,531
  • 8
  • 34