How to plot only a few values from a csv file and how to find their added values?

Hello everyone,

I have a csv.file that shows the amount of meat eaten in different countries in kg per person given at quarterly time.
country. time. kg meat
1 USA. 1980-Q1. 30
2 USA. 1980-Q2. 32
......
32 France. 1980-Q1. 29
33 France. 1980-Q2. 27
....
and so on.

So what I want to do is plot a graph with y-axis showing the country and x-axis showing the time in quarters as described in the data set. But I only want to do this for 2 countries. Not for all. And in addition to that I would like to have the added values which mean USA starts with 30kg second plotting dot would be 30+32 and so on.

I really dont know how to do this. Can someone help me?

Thank you in advance!

Here is an example of manipulating the data with data I invented. Can you do the plot from there?

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#Invent data
DF <- data.frame(Country=rep(c("U","F","C"),each=6),
                 time=rep(c("1980-Q1","1980-Q2","1980-Q3","1980-Q4","1981-Q1","1981-Q2"),3),
                 kg=c(30,32,31,34,29,33,29,27,28,30,26,27,29,30,28,27,26,29))

DF2 <- DF %>% filter(Country %in% c("U","F")) %>% 
  group_by(Country) %>% 
  mutate(CumKg = cumsum(kg))
DF2
#> # A tibble: 12 x 4
#> # Groups:   Country [2]
#>    Country time       kg CumKg
#>    <chr>   <chr>   <dbl> <dbl>
#>  1 U       1980-Q1    30    30
#>  2 U       1980-Q2    32    62
#>  3 U       1980-Q3    31    93
#>  4 U       1980-Q4    34   127
#>  5 U       1981-Q1    29   156
#>  6 U       1981-Q2    33   189
#>  7 F       1980-Q1    29    29
#>  8 F       1980-Q2    27    56
#>  9 F       1980-Q3    28    84
#> 10 F       1980-Q4    30   114
#> 11 F       1981-Q1    26   140
#> 12 F       1981-Q2    27   167

Created on 2020-11-28 by the reprex package (v0.3.0)

1 Like

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.