R 在ggplot2中将x轴原点更改为一个值(非零)
我正在R中生成龙卷风图。我正在使用带有如下代码的R 在ggplot2中将x轴原点更改为一个值(非零),r,ggplot2,R,Ggplot2,我正在R中生成龙卷风图。我正在使用带有如下代码的ggplot2包: dat <- structure(list(variable = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("# of nodes needed", "# of nodes owned", "cost per node"), class = "factor"), Level = structure(c(2L, 2L, 2L, 1L, 1L, 1L), .Label
ggplot2
包:
dat <- structure(list(variable = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("# of nodes needed",
"# of nodes owned", "cost per node"), class = "factor"), Level = structure(c(2L,
2L, 2L, 1L, 1L, 1L), .Label = c("high", "low"), class = "factor"),
value = c(-275, -550, -50, 825, 275, 450)), .Names = c("variable",
"Level", "value"), row.names = c(NA, -6L), class = "data.frame")
ggplot(dat, aes(fill=Level,variable,value )) +
geom_bar(position = 'identity',stat = 'identity') + coord_flip()
dat不确定您是否仍在寻找答案,但我刚刚解决了一个类似的问题。我在scale\u x\u continuous
中使用了limits
和expand
所以我猜对你来说会是这样的:
ggplot(dat, aes(fill=Level,variable,value )) +
geom_bar(position = 'identity',stat = 'identity') +
scale_x_continuous(limits = c(2, 32), expand = c(0, 0))
除了使limits=c(2,32)
成为您想要的x轴极限之外。这意味着你必须手动设置,但我想到的最好的解决办法是做同样的事情 您是否尝试过?xlim
?尝试让您的示例重现。目前,我不知道“结果”中的内容。请阅读以下内容:。最简单的方法是将dput(dat)
的输出复制粘贴到您的问题中。那么当前输出到底有什么问题?“将x轴原点更改为值”是什么意思?你的预期产出是多少?(如果很难解释,你也可能会经过手绘草图/图表的图像)。也许你可以更改标签?