0

I hope my title isn't misleading, unsure how to word this properly.

I have three datasets (BL, BM, BH) with identical columnheaders (7) and rownumbers (1-2412), like this:

https://i.stack.imgur.com/qnmKD.png

This code

ggplot(BL[1334:2413,])+
  geom_step(size=c(2), color = "black",na.rm=TRUE)+
  geom_step(data=BM[1334:2413,], size=c(2), color = "grey",na.rm=TRUE)+
  geom_step(data=BH[1334:2413,], size=c(2), color = "white",na.rm=TRUE)+
  aes(x = timestep, y = cumsum(HarvWood..g.m2.))+
  labs(x="År",y="Avverkning")+
  ylim(0,35000)+
  theme_dark()+
  xlim(2010,2110)+
  ggtitle("Avverkning (kumulativ)")

it creates this graph https://i.stack.imgur.com/kmfvJ.png

How do I create a new graph with the three dataframes on x and the sum of HarvWood..g.m2. on y? Note I only include rows [1334:2413] in all three of them.

Edit: Here are the three files that I am working with. https://www.dropbox.com/sh/w2l9ulvyfrn7rs0/AACKq3mXpmf2zLhS5JgFjUOYa?dl=0

Edit2: I guess I solved it, but only after manually putting the sums into a new df (sum.harv), and then making a barplot out of that.

colSums(BL, na.rm=TRUE)
colSums(BM, na.rm=TRUE)
colSums(BH, na.rm=TRUE)

#sum.harv
Scenario  Harvwood
BL        70716
BM        78808
BH        81248

ggplot(sum.harv)+
    geom_bar(aes(x=Scenario,y=Harvwood, color = Scenario),stat="identity")

Any faster/fancier way of doing it?

s__
  • 9,270
  • 3
  • 27
  • 45
Johan D.
  • 1
  • 1
  • 2
    Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Dec 13 '18 at 19:54
  • Thank you, I edited in a dropbox link with the three files. They are simple textfiles that I imported as datasets into R. – Johan D. Dec 13 '18 at 20:44

0 Answers0