有没有办法在R的三元图上有非重叠的数据点标签?

问题描述 投票:2回答:1

我试图复制我在Qazxswpoi的FiveThirtyEight上找到的图表。这显示了一个静脉图,其中3轴中单词的位置显示了相应网络引用的比例。

我目前正在使用R,ggplot2,更重要的是ggtern(我广泛使用的是ternery情节)。但是我从来没有找到一种方法来使点数据标签不重叠。我一直希望ggtern能与ggrepel互动,但遗憾的是它没有(据我所知)。有没有办法强制这些进行交互,或者找到另一种方法来做这件事?

链接中显示的图表是为了清楚我所追求的:https://fivethirtyeight.com/features/how-cable-news-reacted-to-the-cohen-hearing/

我的图表示例,文字重叠,看起来很糟糕:FiveThirtyEight ternery example

编辑代码来创建我的可怕图表:

Bad ternery plot and bad visualization
r ggplot2 ggtern
1个回答
0
投票

好的,所以你想要 data <- data.frame(word = c("A","random","set","of","words","that","can","hopefully","help","someone","solve","my","issue","of","overlapping","labels","and","make","my","chart","readable","and","a","good","visualization"), axis1 = sample(1:100), axis2 = sample(1:100), axis3 = sample(1:100)) ggtern(data = data, aes(x = axis1, y = axis2, z = axis3, colour = word, label = word)) + geom_point(size = 1) + geom_text() 包中的功能。虽然ggrepel不会在这里工作,你可以使用ggrepelposition_nudge_tern

check_overlap

这将为您提供不重叠的标签:word = c("A","random","set","of","words","that","can","hopefully","help","someone","solve","my","issue","of","overlapping","labels","and","make","my","chart","readable","and","a","good","visualization") col = c("red", "blue", "green", "red", "blue", "green","red", "blue", "green", "red", "blue", "green","red", "blue", "green", "red", "blue", "green","red", "blue", "green", "red", "blue", "green","red") n = 25 #Number of Data Points nv = 0.1 #Vertical Adjustment pn = position_nudge_tern(y=nv,x=-nv/2,z=-nv/2) data <- data.frame(x = sample(1:25), y = sample(1:25), z = sample(1:25), label=word) ggtern(data = data, aes(x = x, y = y, z = z, colour = col, label = word)) + geom_point(size = 1) + theme_nomask() + #Allow Labels to Spool Over Edges geom_text(position=pn,aes(label=word),check_overlap=T, size=5)

© www.soinside.com 2019 - 2024. All rights reserved.