所以我的散点图的一些标签重叠。我曾尝试将 direct.label 与方法“smart.grid”一起使用,但它不会产生适当的结果。这是我目前的图表:
生成它的代码:
ggplot(d, aes(x=ILE2, y=TE,label=d$CA)) +
geom_point(mapping=aes(x=ILE2, y=TE, fill=d$CA), size=9, shape=20, color="black") +
geom_text(data = d,mapping=aes(x=ILE2, y=TE,label=d$CA), size=4, vjust=3, hjust=0.5,size=6)+
geom_smooth(method=lm,se=F)+
theme(legend.position = "none")+
ggtitle("Tasa de Empleo según Índice de Libertad Económica") +
labs(x="Índice de Libertad Económica",y="Tasa de Empleo") +
theme(plot.title = element_text(family =windowsFonts(Times=windowsFont("TT Times New Roman")), color="#666666", face="bold", size=22, hjust=0.5)) +
theme(axis.title = element_text(family =windowsFonts(Times=windowsFont("TT Times New Roman")), color="#666666", face="bold", size=22))
Run Code Online (Sandbox Code Playgroud)
数据:
structure(list(CA = structure(c(1L, 2L, 3L, 4L, 6L, 8L, 9L, 5L,
7L, 10L, 11L, 12L, 14L, …Run Code Online (Sandbox Code Playgroud) 我想使用包直接标签来标记我的情节.但是,我希望标签是每个点的ID.难道真的没有办法选择标注哪个因素或者我错过了哪个因素?
library(ggplot2)
library(directlabels)
df <- structure(
list(id = 1:10,
group = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
.Label = c("A", "B"),
class = "factor"),
value1 = c(4, 1, 6, 2, 5, 7, 3, 2, 5, 8),
value2 = c(6, 2, 6, 2, 8, 9, 7, 5, 2, 6)
),
.Names = c("id", "group", "value1", "value2"),
row.names = c(NA, -10L),
class = "data.frame")
p1 <- ggplot(df, aes(x=value1, y=value2)) + geom_point(aes(colour=group))
direct.label(p1)
Run Code Online (Sandbox Code Playgroud)