Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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 Y轴赢得';t在ggplot中从0开始_R_Ggplot2 - Fatal编程技术网

R Y轴赢得';t在ggplot中从0开始

R Y轴赢得';t在ggplot中从0开始,r,ggplot2,R,Ggplot2,在这个图中,我将ylim排序为0,但是y轴似乎从-1开始,这很烦人。我真的很喜欢y轴统计为0。解决方案 sub1=subset(table.popstat,POPSTAT==1,select=c(1,3)) ggplot(sub1, aes(x=YR,y=Freq)) + ylim(0,15) + geom_bar(stat='identity') + annotate("text",x=3,y=14.9,label="Population status",cex=10) 另外,我有

在这个图中,我将ylim排序为0,但是y轴似乎从-1开始,这很烦人。我真的很喜欢y轴统计为0。解决方案

sub1=subset(table.popstat,POPSTAT==1,select=c(1,3))
ggplot(sub1, aes(x=YR,y=Freq)) + ylim(0,15) +
  geom_bar(stat='identity') + 
  annotate("text",x=3,y=14.9,label="Population status",cex=10)

另外,我有30个这样的图,y轴上有许多不同的范围。我需要一个通用代码,将文本放置在图形的左上角,而不管ymax是什么。可行吗?

ggplot会自动略微延伸轴,以确保有空间放置点进行打印。可以使用expand参数关闭此行为

ggplot(sub1, aes(x=YR,y=Freq)) + 
  geom_bar(stat='identity') + 
  annotate("text",x=3,y=14.9,label="Population status",cex=10) +
  scale_y_continuous(expand = c(0, 0), limits = c(0, 15))

这个函数(扩展(mult=c(0,0.05))可能有帮助

我们不知道数据是什么样子。如果缺少括号,则输出全部或部分的
摘要(table.popstat)
dput()
p + scale_y_continuous(
  limits =   c(0,max_num),
  expand = expansion(mult = c(0,0.05))
)