如何在R中的散点图中设置标签?
如何给R中的散点图命名 例如,在点中我想给出一个玩家的名字如何在R中的散点图中设置标签?,r,data-visualization,R,Data Visualization,如何给R中的散点图命名 例如,在点中我想给出一个玩家的名字 我想说这更像是堆栈溢出的问题。无论如何,这里有一个可能的解决方案,使用ggplot。TIBLE是可选的,它只是数据帧的一个稍微不同的实现。ggrepel使标签出现在旁边,而不是在点上 library(tidyverse) library(ggrepel) mydf <- tibble( player.name = c("john", "jeff", "jake"), average = c(36.6, 29.7, 28
我想说这更像是堆栈溢出的问题。无论如何,这里有一个可能的解决方案,使用ggplot。TIBLE是可选的,它只是数据帧的一个稍微不同的实现。ggrepel使标签出现在旁边,而不是在点上
library(tidyverse)
library(ggrepel)
mydf <- tibble(
player.name = c("john", "jeff", "jake"),
average = c(36.6, 29.7, 28),
strike.rate = c(123.5, 132.9, 136.4)
)
ggplot(mydf, aes(x = average, y = strike.rate, label = player.name)) +
geom_label_repel() +
geom_point()
库(tidyverse)
图书馆(ggrepel)
mydf我认为这更像是堆栈溢出的问题。无论如何,这里有一个可能的解决方案,使用ggplot。TIBLE是可选的,它只是数据帧的一个稍微不同的实现。ggrepel使标签出现在旁边,而不是在点上
library(tidyverse)
library(ggrepel)
mydf <- tibble(
player.name = c("john", "jeff", "jake"),
average = c(36.6, 29.7, 28),
strike.rate = c(123.5, 132.9, 136.4)
)
ggplot(mydf, aes(x = average, y = strike.rate, label = player.name)) +
geom_label_repel() +
geom_point()
库(tidyverse)
图书馆(ggrepel)
mydf另一个选择是使用文本
——可能更简单,但不太美观
noms<-c("Pere","Pau","Indira","Rabindra")
x<-c(3,4,7,5)
y<-c(7,9,12,11)
plot(x,y,xlim=c(3,7.5))
text(x,y,labels=noms,pos=4)
noms另一种选择是使用text
——可能更简单,但不太美观
noms<-c("Pere","Pau","Indira","Rabindra")
x<-c(3,4,7,5)
y<-c(7,9,12,11)
plot(x,y,xlim=c(3,7.5))
text(x,y,labels=noms,pos=4)
noms查看plotly如果您想以交互方式执行,请查看plotly如果您想以交互方式执行,请查看plotly我不认为这比ggrepel
变体更漂亮<如果有很多名字和点的话,code>ggrepel
可能会更好。我不认为这比ggrepel
变体更漂亮<如果有很多名字和点,code>ggrepel
可能会更好。