【发布时间】:2021-06-08 01:01:27
【问题描述】:
所以我有一个包含 2 个变量、一个日期和一个美元价值(盈利或亏损)的简单数据集(实际上是表格)。我正在尝试绘制一个损益图,并让区域 y>0 以绿色阴影显示,y
数据:根据要求,我收集数据的日期包括 4 月 14 日至 9 月 1 日。
dput(upl2$Unrealised.Profit.or.Loss)
c(87.5, -46, 163.5, 194.5, 251.5, 392, 276.5, 424, 354.5, 194,
152, 104, 2, 0, 113, 78.5)
教授或损失代码:
y <- upl2$Unrealised.Profit.or.Loss
loss <- y < 0
prof <- y > 0
even <- y == 0
剧情代码:
ggplot(data = upl2, aes(x=Date, y=Unrealised.Profit.or.Loss, group=1)) +
geom_point() +
theme(axis.text.x = element_text(angle = 60, vjust = 0.5, hjust = 0.5)) +
geom_line(size=.75) +
geom_hline(yintercept=0, size=.5, color = "Blue") +
labs(x = "Date", y = "Unrealised Profit or Loss", title = "Unreaslied Profit or Loss as of 7/6/2021")
任何建议都会很棒,
干杯
【问题讨论】:
-
请
dput(upl2$Unrealised.Profit.or.Loss)并粘贴您的问题以分享您的数据 -
如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则会更容易为您提供帮助。