在线图ggplot2的两边设置space
set space on both sides of line plot ggplot2
我在设置 ggplot2 图表两侧的空白区域时遇到问题。这是我开始使用的数据:
ade <- c(10,7,5,9,6,6,9,4,9,6,5,9,8,7,6,12,7,9,5,5)
adef<-cbind(c(2:21),c(ade/28))
colnames(adef)<-c("pos","f")
adef<-data.frame(adef)
当我非常简单地绘制它时,它看起来不错。
ggplot(data=adef, aes(x=pos, y=f)) +
+ ylim(0,1) +
+ geom_line()
但是,当我尝试更改刻度和标签的数量时发生了意想不到的事情:
ggplot(data=adef, aes(x=pos, y=f)) +
ylim(0,1) +
scale_x_discrete(breaks=c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),
labels=c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21",""))+
geom_line()
我想在右侧添加一个空的 margin/space 以便图表的左右部分看起来一样吗?
您不是在寻找 scale_x_continuous
吗?例如:
ggplot(data=adef, aes(x=pos, y=f)) +
ylim(0,1) +
scale_x_continuous(breaks=2:22, labels=c(as.character(2:21), "")) +
geom_line()
也许 xlim()
and/or expand
scale_*()
中的论点可能会有所帮助。
我在设置 ggplot2 图表两侧的空白区域时遇到问题。这是我开始使用的数据:
ade <- c(10,7,5,9,6,6,9,4,9,6,5,9,8,7,6,12,7,9,5,5)
adef<-cbind(c(2:21),c(ade/28))
colnames(adef)<-c("pos","f")
adef<-data.frame(adef)
当我非常简单地绘制它时,它看起来不错。
ggplot(data=adef, aes(x=pos, y=f)) +
+ ylim(0,1) +
+ geom_line()
但是,当我尝试更改刻度和标签的数量时发生了意想不到的事情:
ggplot(data=adef, aes(x=pos, y=f)) +
ylim(0,1) +
scale_x_discrete(breaks=c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"),
labels=c("2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21",""))+
geom_line()
我想在右侧添加一个空的 margin/space 以便图表的左右部分看起来一样吗?
您不是在寻找 scale_x_continuous
吗?例如:
ggplot(data=adef, aes(x=pos, y=f)) +
ylim(0,1) +
scale_x_continuous(breaks=2:22, labels=c(as.character(2:21), "")) +
geom_line()
也许 xlim()
and/or expand
scale_*()
中的论点可能会有所帮助。