在ggplot中突出显示点的R线图

在ggplot中突出显示点的R线图,r,ggplot2,R,Ggplot2,嗨,我正在试图在ggplot中重新创建下面的图表,我想知道是否有人可以帮助我。突出显示的红色点被视为尖峰 销售卷月份12卷26类型 110670.672.5尖峰 2 92 73.9 73.9条件 39777.174.7尖峰 47577.575.8正常 57477.676.3正常 678.475.8正常 7 76 79.3 75.7正常 8100.875.2尖峰 96879.975.1减少 107379.374.9减少 116478.675.1减少 126077.574.2减少 谢谢, MS这

嗨,我正在试图在ggplot中重新创建下面的图表,我想知道是否有人可以帮助我。突出显示的红色点被视为尖峰

销售卷月份12卷26类型 110670.672.5尖峰 2 92 73.9 73.9条件 39777.174.7尖峰 47577.575.8正常 57477.676.3正常 678.475.8正常 7 76 79.3 75.7正常 8100.875.2尖峰 96879.975.1减少 107379.374.9减少 116478.675.1减少 126077.574.2减少

谢谢,

MS

这个怎么样

library("ggplot2")
library("reshape2")
df <- structure(list(Month = 1:12, Sales = c(106L, 92L, 97L, 
75L, 74L, 78L, 76L, 100L, 68L, 73L, 64L, 60L), Roll12 = c(70.6, 
73.9, 77.1, 77.5, 77.6, 78.4, 79.3, 80.8, 79.9, 79.3, 78.6, 77.5),
Roll26 = c(72.5, 73.9, 74.7, 75.8, 76.3, 75.8, 75.7, 75.2, 
75.1, 74.9, 75.1, 74.2), Type = structure(c(4L, 1L, 4L, 3L, 3L, 
3L, 3L, 4L, 2L, 2L, 2L, 2L), .Label = c("Condition", "Decrease", 
"Normal", "Spike"), class = "factor")), class = "data.frame", row.names = c(NA, 
-12L), .Names = c("Month", "Sales", "Roll12", "Roll26", 
"Type"))

# need to convert the dataframe to long format for plotting; 
# you should change the `variable.name="variable"` and `value.name="value"` args here to whatever you want to call them
df <- reshape2::melt(df, id.vars = c("Month", "Type"))

ggplot(data = df, aes(x = Month, y = value, color = variable)) + 
    geom_line() +
    geom_point(data = df[df[["Type"]] == "Spike" & df[["variable"]] == "Sales", ], color="red")
库(“ggplot2”)
图书馆(“重塑2”)

df请使用例如
?dput()
输入您的数据,而不是发布它的图片。谢谢!这个包裹太棒了