Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在ggplot2中将x轴原点更改为一个值(非零)_R_Ggplot2 - Fatal编程技术网

R 在ggplot2中将x轴原点更改为一个值(非零)

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

我正在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 = 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轴原点更改为值”是什么意思?你的预期产出是多少?(如果很难解释,你也可能会经过手绘草图/图表的图像)。也许你可以更改标签?