【发布时间】:2016-09-09 17:10:35
【问题描述】:
我想绘制一些数据直方图样式。对数据进行了缩放,使得单个观察值的值为 100。但是,数据将按类别分解为文档的单独部分,因此大多数组的最大值不会是 100。
我希望我的绘图使用 log10 y 轴,并使用 固定的 0 到 100 比例 。
以下内容尊重日志转换,但忽略 0-100 范围并发出警告。我尝试了 coord_cartesian(ylim = c(0, 100)) 和 scale_y_continuous(trans = log10_trans()) 的其他排列,但还没有运气。
library(ggplot2)
toread <- "general specific satisfaction
fruit apple 9
fruit apple 8
fruit banana 8
fruit banana 7
fruit pear 6
veg carrot 7
veg celery 4
veg turnip 3
veg turnip 2
veg turnip 1
grain pasta 6
grain quinoa 3
grain brownrice 2
grain brownrice 6"
foodprefs <- read.table(textConnection(toread), header = TRUE)
closeAllConnections()
foodprefs$pct.max <- (foodprefs$satisfaction / max(foodprefs$satisfaction)) * 100
lapply(sort(unique(
as.character(foodprefs$general))), function(one.cat) {
temp <- foodprefs[foodprefs$general == one.cat , ]
ggplot(temp, aes(x = specific, y = pct.max)) +
geom_boxplot() +
ylim(0, 100) +
scale_y_log10() +
coord_flip()
})
【问题讨论】: