[英]Is it possible to have variable width of bars in geom_col?
使用geom_col
時可以選擇更改fill
和col
是否可以更改 geom_col 中條的寬度 - 就像下面的最后一行一樣?
dt <- data.table(diamonds) [ , .(total=.N, price = mean(price)), by = cut]; dt # data.table to work with
ggplot(dt) + geom_col(aes(x=cut, y=price, fill=total)) # we can do this
ggplot(dt) + geom_point(aes(x=cut, y=price, size=total)) # we can do this
ggplot(dt) + geom_col(aes(x=cut, y=price, size=total)) # this does something different
ggplot(dt) + geom_col(aes(x=cut, y=price, width=total)) # this does not work
或者有什么方法可以實現所需的 output - 我需要條形的寬度與total
寬度成正比。
這是一個非常典型的情況:當你 plot 任何關於數據的事情時——你需要顯示這些數據的樣本大小
嘗試這個:
library(ggplot2)
library(data.table)
ggplot(dt) +
geom_col(aes(x=cut, y=price), width = dt$total/100000)
改變寬度參數的分母以改變列的絕對寬度。
由代表 package (v0.3.0) 於 2020 年 6 月 13 日創建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.