我正在尝试从以下数据集中绘制点和线。
dados = structure(list(
Vertices = c(0.5, 1, 1.5, 2, 2.5, 3),
AAA = c(1.8156, 2.2355, 2.4784, 2.6283, 2.7266, 2.7947),
BBB = c(1.9603, 2.3802, 2.6231, 2.773, 2.8713, 2.9394),
CCC = c(2.1559, 2.5758, 2.8188, 2.9686, 3.0669, 3.135)),
row.names = c(NA, 6L), class = "data.frame")
ggplot(data = dados, aes(x = Vertices)) +
#lower points
geom_point(aes(y = AAA, color = "purple")) +
geom_line(aes(y = AAA, color = "purple", linetype ="longdash")) +
#intermediate points
geom_point(aes(y = BBB, color = "blue")) +
geom_line(aes(y = BBB, color="blue", linetype = "dotted")) +
#higher points
geom_point(aes(y = CCC, color = "green")) +
geom_line(aes(y = CCC, color="green", linetype = "dashed")) +
scale_color_manual(values = c("purple", "blue", "green"),
labels = c("AAA","BBB","CCC")) +
ggtitle("Curvas Spread Debentures") +
xlab("Years") + ylab("% points")
#helps visualize numerically
dados
总结:美学颜色未遵循代码顺序
“ AAA”是最小值,应该是紫色,但是以绿色绘制,并且在图例中被指定为“ CCC”。
“ BBB”是中间值,应该是蓝色,但以紫色绘制,并在图例中指定为“ AAA”
“ CCC”是最大值,应该是绿色,但是以蓝色绘制,并在图例中指定为“ BBB”
为了简化,我也尝试只绘制点或仅绘制线,但是颜色和图例也弄乱了。 这是一个非常简单的代码,完全出错了,我看不到错误,有什么想法吗?
你是说要做这样的事吗?