の色を図表のタイトルに追加したいと思います。私はfind some precedent hereにできました。具体的には、アポストロフィで囲まれたテキスト(下の出力)をそれぞれの棒グラフの色に対応させたいと思います。複数のタイトルとR
ここでは、PDFをAdobe Illustratorや他のプログラムにエクスポートする前に、Rでタイトルをどの程度取得したかを説明します。
name <- c("Peter", "Gabriel", "Rachel", "Bradley")
age <- c(34, 13, 28, 0.9)
fake_graph <- family[order(family$age, decreasing = F), ]
fake_graph <- within(fake_graph, {
bar_color = ifelse(fake_graph$name == "Rachel", "blue", "gray")
})
# Plot creation
library(ggplot2)
fake_bar_charts <- ggplot() +
geom_bar(
data = fake_graph,
position = "identity",
stat = "identity",
width = 0.75,
fill = fake_graph$bar_color,
aes(x = name, y = age)
) +
scale_x_discrete(limits = fake_graph$name) +
scale_y_continuous(expand = c(0, 0)) +
coord_flip() +
theme_minimal()
family <- data.frame(name, age)
# Add title
library(grid)
library(gridExtra)
grid_title <- textGrob(
label = "I spend more time with 'Rachel' than\nwith 'other family members.'",
x = unit(0.2, "lines"),
y = unit(0.1, "lines"),
hjust = 0, vjust = 0,
gp = gpar(fontsize = 14, fontface = "bold")
)
gg <- arrangeGrob(fake_bar_charts, top = grid_title)
grid.arrange(gg)
出力:
この例では、棒グラフを作成するだけでなく、タイトル機能のgrid
とgridExtra
するggplot2
を使用していますが、私は、好ましくは、(任意の溶液で働くことをいとわないだろうggplot2
でグラフ自体を作成します)、それぞれの棒グラフの色と一致するテキストを引用符で囲むことができます。このサイト上の
その他のソリューションは、このパズルを解くことができていないが、私はR.
内からこれに対する解決策を見つけるのが大好きだ任意の助けをありがとう!
多分関連:http://stackoverflow.com/questions/35936319/figure-caption-scientific-names-symbols-in-textgrob-gtable – baptiste
HTTPSでのいくつかのコードを持つ:// gthub.com/baptiste/caption – baptiste