- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我的散点图的一些标签重叠。我曾尝试将 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))
structure(list(CA = structure(c(1L, 2L, 3L, 4L, 6L, 8L, 9L, 5L,
7L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 13L), .Label = c("Andalucía",
"Aragón", "Asturias", "Balears", "C. La Mancha", "C. Valenciana",
"C. y León", "Canarias", "Cantabria", "Cataluña", "Extremadura",
"Galicia", "La Rioja", "Madrid", "Murcia", "Navarra", "País Vasco"
), class = "factor"), CA.excel = structure(c(1L, 2L, 3L, 4L,
10L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), .Label = c("Andalucía",
"Aragón", "Asturias, Principado de", "Balears, Illes", "Canarias",
"Cantabria", "Castilla - La Mancha", "Castilla y León", "Cataluña",
"Comunitat Valenciana", "Extremadura", "Galicia", "Madrid, Comunidad de",
"Murcia, Región de", "Navarra, Comunidad Foral de", "País Vasco",
"Rioja, La"), class = "factor"), ILE = c(0.64, 0.45, 0.61, 0.36,
0.4, 0.4, 0.48, 0.54, 0.5, 0.5, 0.72, 0.53, 0.19, 0.49, 0.43,
0.46, 0.39), ILE2 = c(0.36, 0.55, 0.39, 0.64, 0.6, 0.6, 0.52,
0.46, 0.5, 0.5, 0.28, 0.48, 0.81, 0.51, 0.58, 0.54, 0.61), TE = c(39.04,
47.6, 40.61, 48.82, 44.65, 43.06, 45.77, 41.85, 43.49, 49.76,
38.38, 41.82, 53.08, 43.4, 49.49, 47.98, 48.83), migdest = c(21774L,
5511L, 3147L, 9333L, 17187L, 7568L, 2689L, 12547L, 8701L, 19727L,
3878L, 6147L, 38182L, 6678L, 3024L, 7363L, 1736L), Poblacion = c(8399618L,
1326403L, 1049875L, 1124972L, 4939674L, 2126144L, 585359L, 2062767L,
2478079L, 7396991L, 1091623L, 2734656L, 6385298L, 1463773L, 636402L,
2165100L, 313569L), MigraPob = c(0.002592261, 0.004154845, 0.002997501,
0.008296203, 0.003479379, 0.003559496, 0.004593765, 0.006082607,
0.003511188, 0.002666895, 0.003552507, 0.002247815, 0.005979674,
0.004562182, 0.004751713, 0.003400767, 0.005536262), Ocupados = structure(c(3L,
12L, 9L, 10L, 1L, 14L, 5L, 13L, 16L, 7L, 8L, 17L, 4L, 11L, 6L,
15L, 2L), .Label = c("1.836.300", "126.900", "2.683.700", "2.786.600",
"226.300", "258.200", "3.023.200", "350.100", "371.800", "455.900",
"513.400", "524.500", "707.000", "771.500", "870.300", "913.300",
"987.500"), class = "factor"), Activos = structure(c(11L, 15L,
12L, 14L, 6L, 2L, 7L, 17L, 3L, 9L, 13L, 4L, 8L, 16L, 10L, 1L,
5L), .Label = c("1.041.500,00", "1.115.000,00", "1.147.000,00",
"1.263.200,00", "153.900,00", "2.425.100,00", "277.900,00", "3.389.400,00",
"3.781.300,00", "306.100,00", "4.042.900,00", "458.900,00", "501.800,00",
"586.600,00", "644.300,00", "700.300,00", "991.500,00"), class = "factor"),
Tocup = c(0.664, 0.814, 0.81, 0.777, 0.757, 0.692, 0.814,
0.713, 0.796, 0.8, 0.698, 0.782, 0.822, 0.733, 0.844, 0.836,
0.825), Paro = c(0.336, 0.186, 0.19, 0.223, 0.243, 0.308,
0.186, 0.287, 0.204, 0.2, 0.302, 0.218, 0.178, 0.267, 0.156,
0.164, 0.175), X..Emp.disueltas14 = structure(c(9L, 16L,
12L, 15L, 17L, 8L, 14L, 1L, 7L, 4L, 11L, 2L, 13L, 10L, 5L,
3L, 6L), .Label = c("1.102", "1.529", "1.544", "1.953", "160",
"196", "2.465", "260", "3.172", "349", "362", "467", "5.147",
"552", "833", "846", "915"), class = "factor"), EmpD1000h = c(0.3776,
0.6378, 0.4448, 0.7405, 0.1852, 0.1223, 0.943, 0.5342, 0.9947,
0.264, 0.3316, 0.5591, 0.8061, 0.2384, 0.2514, 0.7131, 0.6251
), EmpCreadas = c(15541L, 1933L, 1364L, 2887L, 11206L, 3486L,
819L, 2812L, 3000L, 17664L, 1186L, 4266L, 20268L, 2732L,
905L, 3447L, 448L), TasaEmpC = c(1.850203188, 1.45732481,
1.299202286, 2.566286094, 2.26857076, 1.639587911, 1.399141382,
1.363217465, 1.210615158, 2.387998039, 1.086455672, 1.559976831,
3.174166656, 1.866409614, 1.422057127, 1.592074269, 1.42871266
), RentaMediaHogar = c(21332L, 29120L, 25623L, 26923L, 22392L,
21539L, 23905L, 22271L, 24587L, 30407L, 19364L, 26001L, 31587L,
21269L, 33047L, 34240L, 26666L), GananciaMediaTrab = c(20782.03,
22054.85, 21994.99, 20776.29, 19167.93, 20052.12, 20440.56,
20630.07, 24253.73, 20878.02, 19129.72, 19824.66, 26215.36,
20449.83, 23836.93, 26915.07, 20628.81)), .Names = c("CA",
"CA.excel", "ILE", "ILE2", "TE", "migdest", "Poblacion", "MigraPob",
"Ocupados", "Activos", "Tocup", "Paro", "X..Emp.disueltas14",
"EmpD1000h", "EmpCreadas", "TasaEmpC", "RentaMediaHogar", "GananciaMediaTrab"
), class = "data.frame", row.names = c(NA, -17L))
最佳答案
你可以考虑试试 ggrepel放置标签而不重叠。
library(ggrepel)
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_repel(
data = d,
mapping=aes(x=ILE2, y=TE,label=d$CA),
size=4, size=6, box.padding = unit(0.5, "lines")
)+
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")
关于r - 带有重叠标签的 geom_text(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34473081/
我正在制作多个倾斜条形图的实例。由于计数的大小和百分比的差异不同,在某些情况下,其中一个标签(计数)的一部分被推到栏外。在所有情况下,我都需要标签完全位于栏内。如果不重新定位以适合栏内,我需要标签按原
所以我的散点图的一些标签重叠。我曾尝试将 direct.label 与方法“smart.grid”一起使用,但它不会产生适当的结果。这是我目前的图表: 生成它的代码: ggplot(d, aes(x=
我将 ggplot 与 facet_grid 一起使用,我想在每个方面指示每个方面的观察数量。我遵循许多网站上提供的示例,但是当我让它写任何东西时,它会在所有四个图上将所有四个观察数字都写在彼此之上。
我尝试添加文本,如 Position geom_text on dodged barplot 但它不适用于我的简单数据 data=data.frame(s=c(10,13,17,8),
我想调整条形图上的文本。 我尝试调整 hjust/vjust 以按我喜欢的方式显示,但它似乎无法正常工作。 ggplot(data) + geom_bar(aes(name, coun
我正在尝试复制以下代码( thomasp85/gganimate )。我有两个问题: 我不想显示第一个 geom_point 的标签(变量:partidos); 我希望动画结束后,最后一个 geom_
我正在尝试使用 ggplot 在 R 中绘制堆积条形图。我还想在该片段的每条条中包含百分比。我尝试关注帖子 1 , 2 , 3但这些值并不完全在各自的 block 中。我的数据是 dropbox 中的
我有一个使用 ggplot2 制作的条形图.我想使用 geom_text 为每个条添加标签使得标签的文本大小与标签相对应。为此,我使用了以下代码: a <- aggregate(mpg ~ vs +
在文本中插入数学符号不应该像我想象的那么复杂! OTH,甚至看起来相似的例子 ggplot2 facet_wrap with mathematical expression 我仍然无法将Ω(欧米茄)符
我希望仅在堆积条形图的顶部添加标签。 这是我的数据框: #create data frame building <- c("Burj \nKhalifa", "Zifeng \nTower", "Ba
这里我将 colorRed 设置为 TRUE 所以文本是红色的。但是当我将它设置为 FALSE 时,颜色仍然是红色。 如何根据 colorRed 的值设置文本颜色? library(ggplot2)
所以我正在使用 Twitter API 来收集与特定主题相关的信息,我正在可视化的事情之一是设备的流行程度。 到目前为止,我有这个: https://gyazo.com/441a9ab80b943f9
我正在绘制一个图,其中使用 geom_text 将 p 值绘制为文本。 pvalues 在文件 pvaluesmir21combined 中给出。 如果值 pvaluesmir21combined
我想使用 geom_text()(其中 ^ 表示上标)将“R^2 = 70%”添加到我的绘图中。 没有 % 符号,很简单: my.data <- data.frame(x=1:5, y=1:5) p1
希望这里有人能够帮助我解决我正在尝试解决的 ggplot 脚本问题。脚本会多次使用不同的数据,所以需要比较灵活。我几乎在我想要的地方得到了它,但我遇到了一个我无法解决的问题。 该脚本用于在右侧边距中为
我有一个用 GGplot2 制作的情节。现在,当我想更改图中文本点的大小时,文本的大小不会改变。我使用以下代码行: ggplot(data = out, aes(x = V2, y = V1)) +
我需要更改 geom_text() 中的数字格式包括逗号。 我已经看到了相关的问题,但我无法让这些解决方案发挥作用。我已经尝试过“sep =”一个,count/sum(count) 类型,以及我在不知
使用 mtcars ,我正在为 cyl 创建条形图并填写 gear .没有车 cyl==8 & gear==4 .绘制时,我使用了 position_dodge(preserve = "single"
我的问题 我想用一个表达式来注释 ggplot() 的每个方面,该表达式是统计测试产生的值的组合。我无法在 geom_text() 中解析字符串。 一个类似的问题被部分覆盖了here .不幸的是,我无
请考虑以下最小示例: library(ggplot2) library(ggrepel) ggplot(mtcars) + aes(x = mpg, y = qsec) + geom_line
我是一名优秀的程序员,十分优秀!