ggplot2 には、たとえば 2 行のプロットがあり、凡例には「サメ」と「タイガー」があります。そのテキストの代わりにサメ/トラの画像を凡例に表示する方法はありますか?
2623 次
1 に答える
36
を使用して図をまたはggsave
として保存し、それを Illustrator (または同等のオープン ソース) で開き、凡例を画像に置き換える方がはるかに優れています。すべてを R で行うことに本当に固執している場合は、 in を使用して、 を使用してその横にテキストを追加できます。大まかな試みは次のとおりです。eps
svg
annotation_raster
ggplot2
geom_text
set.seed(10)
library(ggplot2)
library(RCurl)
library(png)
df <- data.frame(animal = sample(c("sharks", "tigers"),20, rep=T), time=1:20,
scariness = rnorm(20)*-20)
shark <- readPNG(getURLContent("http://i.imgur.com/EOc2V.png"))
tiger <- readPNG(getURLContent("http://i.imgur.com/zjIh5.png"))
ggplot(df, aes(time, scariness, group = animal, color = animal)) +
geom_line(show_guide = FALSE) +
annotation_raster(tiger, xmin = nrow(df)-1, xmax = nrow(df),
ymin = max(df$scariness)-(.05*max(df$scariness)),
ymax = max(df$scariness), interpolate = T) +
annotation_raster(shark, xmin = nrow(df)-1, xmax = nrow(df),
ymin = max(df$scariness)-(.1*max(df$scariness)),
ymax = max(df$scariness)-(.05*max(df$scariness)), interpolate = T)
于 2012-10-30T22:54:02.110 に答える