在圖表的第一個方面,我在右上角有一個標題,上面寫著“這很有趣”,但我希望它顯示為:
this is interesting
what now
每次我輸入\n
我都想要一個新行,但我不確定如何在tag_facets()
.
data(iris)
library(ggplot2)
# devtools::install_github("eliocamp/tagger")
library(tagger)
ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) geom_point(aes(color=Species, shape=Species))
xlab("Sepal Length") ylab("Sepal Width")
ggtitle("Sepal Length-Width")
tag_facets(
tag_pool = c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?"),
tag_suffix = "",
position = "tr")
theme(tagger.panel.tag.background = element_rect(fill = "white")) facet_wrap(~Species)
任何指導將不勝感激!
uj5u.com熱心網友回復:
問題是在后臺tagger
使用gridtext::richtext_grob
它允許通過 HTML、CSS 和 markdown 進行格式化,但需要使用<br>
而不是\n
添加換行符:
library(ggplot2)
library(tagger)
tag_pool <- c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?")
tag_pool <- gsub("\\n", "<br>", tag_pool)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width))
geom_point(aes(color = Species, shape = Species))
xlab("Sepal Length")
ylab("Sepal Width")
ggtitle("Sepal Length-Width")
tag_facets(
tag_pool = tag_pool,
tag_suffix = "",
position = "tr"
)
theme(tagger.panel.tag.background = element_rect(fill = "white"))
facet_wrap(~Species)
uj5u.com熱心網友回復:
這是你想要的嗎?
data(iris)
library(ggplot2)
ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width))
geom_point(aes(color=Species, shape=Species))
xlab("Sepal Length") ylab("Sepal Width")
ggtitle("Sepal Length-Width")
facet_wrap(~Species)
geom_label(data = data.frame(x = 6, y = 5, Species = "setosa",
label = "this is interesting\nwhat now"),
aes(x = x, y = y, label = label), size = 4)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/498303.html
上一篇:ggplot2,排序y軸后代
下一篇:為每一行添加可信區間