【问题标题】:Is it possible to use a custom picture as the bars in a bar chart?是否可以使用自定义图片作为条形图中的条形?
【发布时间】:2018-05-26 10:55:06
【问题描述】:

我有想要绘制的数据,而不是显示 y 轴值的常规垂直条,我想要:

1) 用图片填充栏(例如圣诞装饰图案)

2) 使用自定义图片(比如蜡烛)作为条形

这可能吗?我的首选平台是 R、Excel 或 Tableau public。

【问题讨论】:

  • 在 R 中,这会很困难,需要破解或变通方法。这是设计使然。可爱的图片很少为图形添加额外的信息或清晰度,因此图形包的作者通常不包含添加图片的功能。

标签: r excel data-visualization tableau-api business-intelligence


【解决方案1】:

在 excel 2013 中,您可以使用图像文件填充图表中的列。通过右键单击选择列,然后从弹出菜单中选择格式数据点。选择油漆桶选项卡,在填充选项下选择图片或纹理填充,然后从文件中插入图片。图像现在覆盖在图表的列上。

【讨论】:

    【解决方案2】:

    你可以试试

    library(jpeg)
    library(grid)
    library(lattice)
    
    #download Chrismas tree image which will be used as bar in barplot
    download.file("https://upload.wikimedia.org/wikipedia/commons/f/fa/Poinsettia_tree.jpg", "Poinsettia_tree.jpg")
    chrismas_tree <- readJPEG("Poinsettia_tree.jpg")
    
    #sample data for barplot
    counts <- table(mtcars$gear)
    
    #barplot
    barchart(counts, origin=0, col="white",horizontal = FALSE,
                 panel=function(x, y, ...) {
                 panel.barchart(x, y, ...)
                 grid.raster(chrismas_tree, y=0, height=y, x=x,
                                   default.units="native", 
                                   just="bottom",
                                   width=unit(0.2,"npc"))
                 },
             ylab = "Counts",
             xlab = "Gear",
             main = "Gear counts plot (mtcars)")
    

    【讨论】:

    • 这太棒了
    • @Siva - 在R
    • @Prem 很棒,我们如何在画面中嵌入 R?你能提供一些见解吗?
    • @Siva 希望this 可以帮助您入门。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    相关资源
    最近更新 更多