我在这里查看了很多答案,但无法解决我的问题 - 所以我想在这里问。我想我需要调用这个因素?我不能让它工作。我正在从 excel csv 文件中导入我的数据。
我希望将图例组织起来 Hypolimnion, Metalimnion (Bottom), Metalimnion (Top), Epilimnion
我也不明白为什么九月没有出现在我的 x 轴上
我只包括我的数据的一个子集
Date Reservoir Result
9/24/2019 Epilimnion 0.03
9/24/2019 Metalimnion (Top) 0.06
9/24/2019 Metalimnion (Bottom) 0.9
9/24/2019 Hypolimnion 1.63
10/8/2019 Epilimnion 0.03
10/8/2019 Metalimnion (Top) 0.13
10/8/2019 Metalimnion (Bottom) 0.81
10/8/2019 Hypolimnion 1.45
TP<-read.csv("TP.csv", header=TRUE)
library(ggplot2)
library(scales)
TP$Date <- as.Date(TP$Date, "%m/%d/%Y")
p<-ggplot(TP, aes(x=Date, y=Result, group=Reservoir, color=Reservoir)) +
theme(plot.title = element_text(hjust = 0.5)) + xlab("") + ylab("Total Phosphorus (mg/L)") +
geom_point(size = 4) +
theme(axis.text.x = element_text(angle = 45, vjust = 1.0, hjust = 1.0)) +
scale_x_date(breaks = date_breaks("1 month"), labels = date_format("%b %Y")) +
geom_hline(yintercept
= 0.1, linetype = 2, colour='turquoise4', size = 1) +
theme(legend.position="bottom") + theme(legend.title=element_blank())
p<-p+expand_limits(y=0)
p + scale_y_continuous(expand = c(0, 0.1))
这是我试图根据下面的出色响应重新创建的代码
setwd("P:/Projects/Coleman Engineering/Products/R work")
TP<-read.csv("TP.csv", header=TRUE)
library(lubridate)
library(ggplot2)
library(scales)
ggplot(TP, aes(x = mdy(Date), y = Result, color = Reservoir))+
geom_point(size = 4)+
ylab("Total Phosphorus (mg/L)") +
scale_x_date(name = "", breaks = date_breaks("1 month"), labels =
date_format("%b %Y"), limits = c(mdy("08/30/2019"),mdy("1/30/2020"))) +
scale_color_discrete(labels = c("Hypolimnion", "Metalimnion (Bottom)",
"Metalimnion (Top)", "Epilimnion"), breaks = c("Hypolimnion",
"Metalimnion(Bottom)", "Metalimnion(Top)", "Epilimnion"))+
geom_hline(yintercept = 0.1, linetype = 2, colour='turquoise4', size = 1)
+ theme(legend.position="bottom",
axis.text.x = element_text(angle = 45, vjust = 1.0, hjust = 1.0),
legend.title=element_blank(),
plot.title = element_text(hjust = 0.5))


