I have a dataset like this:
I want to show the trend, the x-axis containing the year values and the y-axis the corresponding values from the columns, so Maybe
ggplot(data,aes(year,bm))
I want to not just plot one column but Maybe more of them. As in one plot it seems to be too much detailed I wanted to make use of facet_grid to arrange the plots nicely next to eacht other. However It did not work for my data as I think I have no 'real' objects to compare. Does anyone has an idea how to I can realize facet_grid so it loos like something like this (in may case p1=BM and p2=BMSW):
The problem is your data format. Here is an example with some fake data
library(tidyverse)
##Create some fake data
set.seed(3)
data <- tibble(
year = 1991:2020,
bm = rnorm(30),
bmsw = rnorm(30),
bmi = rnorm(30),
bmandinno = rnorm(30),
bmproc = rnorm(30),
bmart = rnorm(30)
)
##Gather the variables to create a long dataset
new_data <- data %>%
gather(model, value, -year)
##plot the data
ggplot(new_data, aes(x = year, y = value)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
facet_grid(~model)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.