r中一个变量的折线图,如何着色?
Line graph for one variable in r, how to color?
所以我认为使用以下内容会很简单:
df <- structure(list(time_bin = c("00", "01", "02", "03", "04", "05",
"06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23"), count = c(33L, 35L,
35L, 27L, 24L, 22L, 47L, 73L, 84L, 90L, 131L, 122L, 91L, 97L,
78L, 70L, 56L, 50L, 54L, 37L, 40L, 25L, 24L, 31L)), row.names = c(NA,
-24L), class = c("tbl_df", "tbl", "data.frame"))
并使用下面的代码,得到一个具有下面指定颜色的图。然而这仍然没有情节......
ggplot(time_bin_counts, aes(y=count, x=as.factor(time_bin), color = "mediumpurple2" )) +
geom_line() +
labs(x = "Day of the Week", y = "Injury", fill = "") +
lims(y = c(0,150)) +
theme_hc() +
theme(axis.text.x=element_text(angle = 45))
你可以试试这个:
ggplot(df, aes(y=count, x=as.factor(time_bin),group=1 )) +
geom_line(color = "mediumpurple2") +
labs(x = "Day of the Week", y = "Injury", fill = "") +
lims(y = c(0,150)) +
theme(axis.text.x=element_text(angle = 45))
输出:
所以我认为使用以下内容会很简单:
df <- structure(list(time_bin = c("00", "01", "02", "03", "04", "05",
"06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23"), count = c(33L, 35L,
35L, 27L, 24L, 22L, 47L, 73L, 84L, 90L, 131L, 122L, 91L, 97L,
78L, 70L, 56L, 50L, 54L, 37L, 40L, 25L, 24L, 31L)), row.names = c(NA,
-24L), class = c("tbl_df", "tbl", "data.frame"))
并使用下面的代码,得到一个具有下面指定颜色的图。然而这仍然没有情节......
ggplot(time_bin_counts, aes(y=count, x=as.factor(time_bin), color = "mediumpurple2" )) +
geom_line() +
labs(x = "Day of the Week", y = "Injury", fill = "") +
lims(y = c(0,150)) +
theme_hc() +
theme(axis.text.x=element_text(angle = 45))
你可以试试这个:
ggplot(df, aes(y=count, x=as.factor(time_bin),group=1 )) +
geom_line(color = "mediumpurple2") +
labs(x = "Day of the Week", y = "Injury", fill = "") +
lims(y = c(0,150)) +
theme(axis.text.x=element_text(angle = 45))
输出: