ドーナツグラフのラベルの位置をグラフの右側に移動しようとしていますが、移動できません。グラフを作成するためにggplotとggrepelを使用しています。
library(ggplot2)
library(ggrepel)
expenditurePie = data.frame(
value = c(98,2),
area = c("A","B"),
label = c("","This is a label"))
ggplot(expenditurePie, aes(y=value, fill = area, label = label)) +
geom_bar(aes(x = 4), stat = "identity", show.legend = F) +
geom_text_repel(size = 5, x= 4, point.padding = unit(1.8, "lines"), direction = "x") +
xlim(0.5, 4.5) +
annotate(geom = "text", x=0.5, y=0, label = "24 444", size = 16, color = "grey") +
scale_fill_manual(values = c(A = "grey", B = "black")) +
coord_polar(theta = "y", start = 1) +
theme_void() +
theme(legend.position = 'none')
どうすればいいですか?ありがとう。
多分これはあなたのためのオプションです。ggrepel
私のアプローチの魔法に頼る代わりに、手動で(まだ使用してggrepel
いますが、力を0に設定して)ラベルを設定し、を使用してセグメントを描画しますgeom_segement
。これを試して:
library(ggplot2)
library(ggrepel)
expenditurePie = data.frame(
value = c(98,2),
area = c("A","B"),
label = c("","This is a label"))
ggplot(expenditurePie, aes(y = value, fill = area, label = label)) +
geom_bar(aes(x = 4), stat = "identity", show.legend = F) +
geom_text_repel(size = 5, x = 7, point.padding = unit(1.8, "lines"), direction = "x", force = 0, seed = 42) +
geom_segment(aes(x = 4.6, xend = 5.5, y = 1, yend = 1)) +
xlim(0.5, 5.5) +
annotate(geom = "text", x=0.5, y=0, label = "24 444", size = 20, color = "grey") +
scale_fill_manual(values = c(A = "grey", B = "black")) +
coord_polar(theta = "y", start = 1) +
theme_void() +
theme(legend.position = 'none')
reprexパッケージ(v0.3.0)によって2020-05-25に作成されました
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加