是否可以将自定义图片用作条形图中的条形? [英] Is it possible to use a custom picture as the bars in a bar chart?
本文介绍了是否可以将自定义图片用作条形图中的条形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有想要绘制的数据,并且我不想显示y轴值的常规垂直条,而是选择其中一种:
I have data that I'd like to plot, and instead of regular vertical bars showing the value of the y-axis, I'd like to either:
1)用图片(例如圣诞节装饰图案)填充酒吧
1) fill up the bar with a picture (a Christmas ornament pattern, for example)
2)使用自定义图片(例如蜡烛)作为栏
2) use a custom picture (such as a candle, let's say) as the bar
这可能吗?我首选的平台是R,Excel或Tableau public.
is this possible? My preferred platform is either R, Excel, or Tableau public.
推荐答案
您可以尝试
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)")
这篇关于是否可以将自定义图片用作条形图中的条形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文