[英]Adding Custom Legend to 2 Data sets in ggplot2
我试图在Nyquist图中简单地添加一个图例,在其中绘制2组数据:1是实验组(〜600点),而2是使用传递函数计算的数据框(〜1000点)
我需要同时绘制和标记它们。 目前,我都把它们都绘制好了,但是当我尝试使用scale_colour_manual添加标签时,没有标签出现。 还可以通过这种方式来移动此标签! 下面的代码。
pdf("nyq_2elc.pdf")
nq2 <- ggplot() + geom_point(data = treat, aes(treat$V1,treat$V2), color = "red") +
geom_point(data = circuit, aes(circuit$realTF,circuit$V2), color = "blue") +
xlab("Real Z") + ylab("-Imaginary Z") +
scale_colour_manual(name = 'hell0',
values =c('red'='red','blue'='blue'), labels = c('Treatment','EQ')) +
ggtitle("Nyquist Plot and Equivilent Circuit for 2 Electrode Treatment Setup at 0 Minutes") +
xlim(0,700) + ylim(0,700)
print(nq2)
dev.off()
Ggplot最适合长数据框,因此我将像这样组合数据集:
treat$Cat <- "treat"
circuit$Cat <- "circuit"
CombData <- data.frame(rbind(treat, circuit))
ggplot(CombData, aes(x=V1, y=V2, col=Cat))+geom_point()
这应该给您想要的图例。
您可能必须更改数据框treat
和circuit
的列的名称/顺序,以便可以将它们组合在一起,但是很难说,因为您没有给我们提供可复制的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.