我的数据:
Country Year FY_sales Truck_type GDP Inflation_Rate Unemployment_Rate
1 France 2007-05-25 2064543 LCV 2663112510266 1.488073528 7.659999847
2 France 2007-05-25 460552 MCV/CV 2663112510266 1.488073528 7.659999847
3 France 2007-05-25 58940 HCV 2663112510266 1.488073528 7.659999847
我想这样画:
我为gdp绘制了
ggplot(data,aes(Year,gdp))+geom_line()+geom_point()
但我需要gdp,通货膨胀,同样的失业率。
答案 0 :(得分:0)
这是一个帮助您的简单示例
set.seed(5)
# example data
dt = data.frame(id = 1:4,
x = runif(4),
y = runif(4),
z = runif(4))
library(tidyverse)
dt %>%
gather(var, value, -id) %>% # reshape data
ggplot(aes(id, value, col=var))+ # plot using different colour for each variable
geom_point()+
geom_line()
答案 1 :(得分:0)
我这样做
library(data.table)
setDT(dt)
dataGraf <- rbind(data[ ,.(Year, value = Unemployment_Rate, Type = "Unemployment_Rate")],
data[ ,.(Year, value = Inflation_Rate, Type = "Inflation_Rate")],
data[ ,.(Year, value = GDP, Type = "GDP")])
ggplot(dataGraf,aes(Year, value, color = Type))+geom_line()+geom_point()