我有三个股票的价格线图,我通过从我看到的期间开始时的百分比变化来标准化。这似乎可以正常工作,但我不想在当前构成图例关键字的灰色背景上使用彩色线条,而想在关键标签旁边显示正方形或圆圈。用符号替换geom_line的ggplot2图例密钥
这甚至可能在ggplot2?任何指针,无论简短,赞赏。编制图表的代码如下所示。
Date <- c("2011-09-19","2011-09-20","2011-09-21","2011-09-22",
"2011-09-23","2011-09-26","2011-09-27","2011-09-28","2011-09-29","2011-09-30")
CoA <- c(100,100,95,93,88,91,98,109,115,106)
CoB <- c(16.5,16.8,17.2,17,17.5,16.5,16,15.5,16.1,16.3)
CoC <- c(3.2,3.18,3.15,3.12,3.15,3.1,3.08,3.11,3.35,3.42)
prices <- data.frame(Date,CoA,CoB,CoC)
changes <- as.data.frame(matrix(nrow=nrow(prices),ncol=ncol(prices)))
changes[,1]=prices[,1]
for(i in 2:ncol(prices)){ # calculate changes in price
changes[,i]= (prices[,i]-prices[,i][1])/prices[,i][1]
}
colnames(changes) <- colnames(prices)
changes <- melt(changes, id = "Date")
changes$Date <- as.Date(as.character(changes$Date))
chart1 <- ggplot(data=changes,aes(x=changes$Date,y=changes$value,colour=changes$variable))
chart1 <- chart1 + geom_line(lwd=0.5) + ylab("Change in price (%)") + xlab("Date") +
labs(colour="Company")
print(chart1)
谢谢,非常有趣。将学习和适应。 – SlowLearner