我正在绘制相关散点图,其中我的数据框包含时间数据,并且起始年份是任意的。在这种情况下,现在我有以下内容R
code
## Set seed for randomness in dummy data: ##
set.seed(123)
## Create data frame: ##
df.Data <- data.frame(date = seq(as.Date('2019-01-01'), by = '1 day', length.out = 650),
DE = rnorm(650, 2, 1), AT = rnorm(650, 5, 2))
corPearson <- cor.test(x = df.Data$DE, y = df.Data$AT, method = "pearson")
df.Data$year <- format(as.Date(df.Data$date), '%Y')
## PLOT: ##
p <- ggplot(data = df.Data, aes(x = DE, y = AT, group = 1)
) +
geom_point(aes(color = year)) +
geom_smooth(method = "lm", se = FALSE, color = "#007d3c") +
theme_classic() +
theme(legend.position = "none") +
theme(panel.background = element_blank()) +
scale_colour_brewer(palette = 'Greens') +
xlab("PEGAS TTF M1") +
ylab("EEX DEB M1") +
ggtitle("Correlation Scatter Plot (Pearson)") +
theme(plot.title = element_text(hjust = 0.5, face = "bold"))
## Correlation plot converting from ggplot to plotly: #
CorrelationPlot <- plotly::ggplotly(p, tooltip = "text")
给出以下输出:
我的问题在于调色板。我用Greens
调色板,它以比 2019 年的数据更深的绿色绘制 2020 年的数据,我希望保持原样。
尽管如此,我希望它从较深的绿色开始,例如红色箭头绿色表示 2020 年的数据,蓝色箭头绿色表示 2019 年数据。
我怎样才能做到这一点?