我想绘制一个双面条形图,其中距离中心线2的距离与相对侧的距离0.5相同(而5与另一侧的距离相同) - 因为值代表商(偏好或回避) 我试过这样的话:
df <- data.frame(value=c(2, 0.5, 4, 0.25, 1, 0.3, 4,2, 3, 0.2 ,0.5, 0.4), group = rep(c("I","II","III"), 4), class = rep(c("a","b","c","d"), 3))
df$rez <-ifelse(df$value < 1,-( 1/df$value),df$value)
newlab <- c("1/5","1/4", "1/3", "1/2","1", "2", "3", "4", "5")
library (ggplot2)
p <- ggplot(df, aes(factor(class), rez, fill = group)) +
geom_bar(stat="identity",width = 0.5, position = position_dodge(width = 0.5)) +
scale_y_continuous(limits = c(-5,5),breaks = c(-5, -4, -3, -2, 0,2, 3, 4, 5), labels = newlab)
p
但标签之间的间距不正确。
答案 0 :(得分:0)
found a way; scale_y_log10() does the job:
p <- ggplot(df, aes(class, value, fill = group)) + geom_col(width = 0.5, position = position_dodge(width = 0.5))
p + scale_y_log10(breaks = c(0.2, 0.5, 1, 2, 3, 4))