line graph is broken

hi i am a uni student right now i am cant seem to plot a line graph . I am trying to filter the most common 4 gennera by count and then show the counts over the year by using a line graph . Any help or suggesions would help me alot. Thank you!!

library(tidyverse)
rodents_small <-read_tsv("https://bit.ly/rodents_small")
rodents_small3<- filter(rodents_small , genus == "Dipodomys"| genus=="Chaetodipus"|genus=="Onychomys"|genus=="Reithrodontomys")
count(rodents_small3,genus)
rodents_small4 <-filter(rodents_small3)
count(rodents_small4,year)
rodents_small4
ggplot(data = rodents_small4 , aes(x = genus, y=weight  ))+geom_line()+ facet_wrap(~genus)

Here are some comments on your code. I understand you want to plot count vs. year.

library(tidyverse)
rodents_small <-read_tsv("https://bit.ly/rodents_small")
rodents_small3<- filter(rodents_small , genus == "Dipodomys"| genus=="Chaetodipus"|genus=="Onychomys"|genus=="Reithrodontomys")
count(rodents_small3,genus) # displays a result but does not store it in a variable.
rodents_small4 <-filter(rodents_small3) #Does not change anything because there are no filter conditions
count(rodents_small4,year) # displays a result but does not store it in a variable.
rodents_small4

#You do not mention the year or the count variable (n) in the ggplot call
ggplot(data = rodentsm_small4 , aes(x = genus, y=weight  ))+geom_line()+ facet_wrap(~genus)

Is this close to what you want?

  library(tidyverse)
  rodents_small <-read_tsv("https://bit.ly/rodents_small")
#> Rows: 30738 Columns: 13
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: "\t"
#> chr (6): species_id, sex, genus, species, taxa, plot_type
#> dbl (7): record_id, month, day, year, plot_id, hindfoot_length, weight
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
  rodents_small3<- filter(rodents_small , genus == "Dipodomys"| genus=="Chaetodipus"|genus=="Onychomys"|genus=="Reithrodontomys")
  rodents_small4 <- count(rodents_small3,year,genus)
  rodents_small4
#> # A tibble: 104 × 3
#>     year genus               n
#>    <dbl> <chr>           <int>
#>  1  1977 Chaetodipus         3
#>  2  1977 Dipodomys         222
#>  3  1977 Onychomys           5
#>  4  1977 Reithrodontomys     2
#>  5  1978 Chaetodipus        23
#>  6  1978 Dipodomys         629
#>  7  1978 Onychomys          80
#>  8  1978 Reithrodontomys     2
#>  9  1979 Chaetodipus        19
#> 10  1979 Dipodomys         394
#> # … with 94 more rows
  ggplot(data = rodents_small4 , aes(x = year, y=n  ))+geom_line()+ facet_wrap(~genus)

Created on 2022-10-15 with reprex v2.0.2

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.