我在ggplot2中繪製了一個圖,例如2行,在圖例中我有「鯊魚」和「老虎」。有沒有辦法讓鯊魚/老虎圖像出現在圖例中而不是文字中?在ggplot2圖例中使用圖片代替標籤
11
A
回答
32
使用ggsave
將圖保存爲eps
或svg
,然後在Illustrator中打開它(或等效的開放源代碼)並用圖像替換圖例,會更好。如果您真的死於R這一切,您可以在當前ggplot2
中使用annotation_raster
,並使用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)
相關問題
- 1. ggplot2中的圖例標籤
- 2. 用多級ggplot2圖中的標籤替換圖例
- 3. ggplot2線圖圖例文本標籤
- 4. ggplot2中的動態圖例標籤
- 5. ggplot2更改圖例中的標籤
- 6. 如何在ggplot2圖例標籤中添加Latex代碼?
- 7. 在WPF中使用圖片或圖標代替DataGridCheckBoxColumn
- 8. 使用替代文本查找圖片標籤
- 9. Angular 2 - 使用芯片代替標籤
- 10. 圖例中GGPLOT2
- 11. ggplot2:使用每個第N個圖例密鑰標籤
- 12. 我可以用CSS替換圖片標籤的圖片嗎?
- 13. 在R中使用ggplot2修改圖例
- 14. 在ggplot2中移動圖例標題
- 15. ggplot2散點圖標籤
- 16. R - 使用空標籤將ggplot2圖形中的NA標籤轉換爲圖形
- 17. ggplot2:動態圖例標題
- 18. R線圖ggplot2的手動圖例標籤
- 19. 圖片標籤
- 20. 圖片標籤
- 21. ggplot2:餅圖代替xy scatterplot中的點
- 22. 從ggplot2中的圖例中刪除選定的標籤(因素)
- 23. 如何在ggplot2圖例中使用下標[R]
- 24. 在R/ggplot2中修改堆疊面積圖的圖例和標籤
- 25. 替代圖片框?
- 26. 用jQuery替換img標籤使用JavaScript替代幻燈片
- 27. 如何格式化ggplot2圖例中的標籤?
- 28. 我如何手動更改ggplot2圖例中的鍵標籤值?
- 29. ggplot2中的圖例標題位置
- 30. RStudio ggplot2圖例中未顯示圖例
我不會說這是不可能的,但你R中得到任何的解決方案很可能是WAAAAY不是簡單地發射了Photoshop的困難。 (不過,看看'grid.raster'可能會讓你開始吧。) – joran
或[gimp](http://www.gimp.org/)是爲那裏的開源愛好者準備的。 – Chase
是的,在光柵程序中手工操作是不行的,這是用於大規模重複圖形生成:) – nicolaskruchten