0

For the life of me I cannot get my plot points to connect. They are invisible or try to connect every single dot in a crazy jagged line. My data looks like

 df <- read.table(text = "year      variable       value
           2018-19 estimated.males 666
           2019-20 estimated.males 734
           2020-21 estimated.males 682
           2018-19 estimated.females   356
           2019-20 estimated.females   342
           2020-21 estimated.females   351
           2018-19 total   1022
           2019-20 total   1076
           2020-21 total   1033", header = T)

my code is as follows

 ggplot(df, aes(x = year, y = value, colour= variable, shape = variable), group = 1) + 
  geom_point()+
  geom_path(aes(colour= variable))+
  geom_text(aes(label = value), size = 3, colour = "black")+
  theme(axis.line= element_line(colour= "black"), panel.background= element_blank(),
        axis.text.x = element_text(angle = 30, hjust = 1, vjust = 1))+
  labs(x= "Year", y= "Estimation Harvested", 
       title = "Harvest Estimation")

Any suggestions on how to straighten this issue out? enter image description here

tjebo
  • 21,977
  • 7
  • 58
  • 94
Jena
  • 27
  • 5
  • 2
    instead of group = 1, use group = variable (inside aes!!) – tjebo Dec 29 '21 at 00:20
  • 1
    Does this answer your question? [Using \`geom\_line()\` with X axis being factors](https://stackoverflow.com/questions/16350720/using-geom-line-with-x-axis-being-factors) – tjebo Dec 29 '21 at 00:23
  • 1
    @tjebo the first suggestion you made worked! Thank you! – Jena Dec 29 '21 at 15:18

0 Answers0