我目前正试图绘制一幅线条图,表示在各种类型的手术中医生人数在3年中的演变情况(每行一行),我的数据如下所示:
type of operation number of doctors year
ambulatoire 12 2019
externe 150 2019
ambulatoire 19 2020
externe 3 2020
我试过下面的代码,但似乎行不通.有人能帮忙吗?
ggplot(df) +
geom_line(aes(x = df$year, y = df$"number of doctors", color = df$"type of operation"))
发布于 2022-06-21 12:38:57
尝尝这个
library(ggplot2)
df <-
data.frame(
type_of_operation = c("ambulatoire", "externe"),
number_of_doctors = c(12, 150, 19, 3),
year = c(2019, 2019, 2020, 2020)
)
ggplot(df, aes(x = year, y = number_of_doctors, color=type_of_operation)) +
geom_line()
PS :如果要在变量名中保留空间,请使用以下引号:‘而不是’
发布于 2022-06-21 12:39:43
尝尝这个
ggplot(df) +
geom_line(aes(x = year,
y = `number of doctors`,
color = `type of operation`))
https://stackoverflow.com/questions/72700850
复制相似问题