R:如何在图形中绘制对角线

时间:2017-11-22 15:37:44

标签: r ggplot2

我用ggplot2创建了一个图形,我想从左下角到右上角添加一条对角线,并将颜色添加到此行。我怎么能这样做?

ggplot(data, aes(x=DRTG, y=ORTG)) +
  geom_point(colour = "#000000") + 
  ggtitle("Gráfico: Ratio Defensivo / Ratio Ofensivo (hasta jornada 8)") +
  geom_text(label=rownames(data), colour = "#000000", nudge_x = 0, nudge_y = 0.75, size = 4, vjust = "inward", hjust = "inward", check_overlap = F) +
  geom_point(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, colour="red", size = 1)) + 
  geom_vline(xintercept = pointMedia[, "mediaDRTG"], colour = "green") + 
  geom_hline(yintercept = pointMedia[, "mediaORTG"], colour = "blue") +
  geom_text(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, nudge_x = 0, nudge_y = 0.75, label="Liga DIA")) +
  theme(legend.position = "none")

enter image description here

编辑I:

我添加了+ geom_abline(拦截= 120,斜率= 0)并且我什么都没得到:(我做错了什么?

ggplot(data, aes(x=DRTG, y=ORTG)) +
  geom_point(colour = "#000000") + 
  ggtitle("Gráfico: Ratio Defensivo / Ratio Ofensivo (hasta jornada 8)") +
  geom_text(label=rownames(data), colour = "#000000", nudge_x = 0, nudge_y = 0.75, size = 4, vjust = "inward", hjust = "inward", check_overlap = F) +
  geom_point(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, colour="red", size = 1)) + 
  geom_vline(xintercept = pointMedia[, "mediaDRTG"], colour = "green") + 
  geom_hline(yintercept = pointMedia[, "mediaORTG"], colour = "blue") +
  geom_text(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, label="Liga DIA"), nudge_x = 0, nudge_y = 0.75) +
  geom_abline(intercept = 120, slope = 0) +
  theme(legend.position = "none")

编辑II:

我设置了拦截和斜率到这个值,我得到了这张照片

ggplot(data, aes(x=DRTG, y=ORTG)) +
  geom_point(colour = "#000000") + 
  ggtitle("Gráfico: Ratio Defensivo / Ratio Ofensivo (hasta jornada 8)") +
  geom_text(label=rownames(data), colour = "#000000", nudge_x = 0, nudge_y = 0.75, size = 4, vjust = "inward", hjust = "inward", check_overlap = F) +
  geom_point(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, colour="red", size = 1)) + 
  geom_vline(xintercept = pointMedia[, "mediaDRTG"], colour = "green") + 
  geom_hline(yintercept = pointMedia[, "mediaORTG"], colour = "blue") +
  geom_text(data=pointMedia, aes(x=mediaDRTG, y=mediaORTG, label="Liga DIA"), nudge_x = 0, nudge_y = 0.75) +
  geom_abline(intercept = 11.6, slope = 1) +
  theme(legend.position = "none")

enter image description here

我想要的是该行的结尾位于图表的右上角。

我想从图表的左下角画一条直到图的右上角。

0 个答案:

没有答案