[英]plot names of columns in R?
這是我的數據集的一個子集:
structure(list(zone = c(3L, 4L, 2L), la3 = c(1,
6, 3), la4 = c(3, -2, 5)), row.names = c("1",
"2", "3"), class = "data.frame")
如何將它們繪制(ggplot2)作為x軸上的列名(la3和la4)以及y軸上的區域名?
如果要在同一圖上繪制la3
和la4
,則需要先將數據轉換為“長”格式。 您可以使用geom_text
或geom_label
添加標簽,但我強烈建議使用ggrepel
軟件包將標簽添加到繪圖中,並建議使用geom_text_repel
或geom_label_repel
函數。
library(tidyverse)
library(ggrepel)
ggplot(data %>% gather(key=la, ...=-zone)) +
geom_point(aes(la, value, color=as.character(zone))) +
geom_text_repel(aes(la, value, label=zone))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.