我已经使用ggplot2制作了一个小节,需要提交的Journal要求该轴刻度线朝内。
这是我的数据的文字表示(dput)
Mean.Inc.melt<-structure(list(Var1 = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Harvest","Pre-Harvest"), class = "factor"), Var2 = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label =c("Dip A", "Trip A", "Trip B"), class = "factor"), value = c(2, 34, 1, 36, 3, 46)), .Names =c("Var1", "Var2", "value"), row.names = c(NA, -6L), class = "data.frame")
包括标准误差
SEM.Inc.melt<-structure(list(Var1 = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Harvest", "Pre-Harvest"), class = "factor"), Var2 = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Dip A", "Trip A", "Trip B"), class = "factor"), value = c(1, 12, 1, 2, 1, 6)), .Names = c("Var1", "Var2", "value"), row.names = c(NA, -6L), class = "data.frame")
到目前为止,这是我用来创建情节的脚本:
ggplot(Mean.Inc.melt,aes(x=Var2,y=value,fill=Var1))+
geom_bar(stat='identity',position=position_dodge(),colour='black')+
scale_fill_manual(values=c('#000000','#FFFFFF'))+
geom_errorbar(aes(ymin=Mean.Inc.melt$value-SEM.Inc.melt$value,
ymax=Mean.Inc.melt$value+SEM.Inc.melt$value),width=.1,
position=position_dodge(.9))+
xlab('Treatment')+
ylab('Percentage Incidence (%)')+
ylim(0,60)+
scale_y_continuous(expand=c(0,0),limits=c(0,60))+
scale_x_discrete(expand=c(0,0))+
theme_bw()+
theme(axis.line=element_line(colour='black'),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),panel.border=element_blank(),
panel.background=element_blank())+
geom_vline(xintercept=0)+theme(legend.position='none')
我想关键是-有人知道我是否可以使轴面向内吗?
最佳答案
虽然我不了解期刊希望在内部加上刻度线,但使用ggplot
实现这一点非常简单。
axis.ticks.length
的theme
参数允许您设置刻度线的长度。如果将其设置为负值,刻度线将向内绘制。例如(通过Dennis Murphy here重新发布解决方案):
library(ggplot2)
library(grid)
ggplot(mtcars, aes(disp, mpg)) + geom_point() +
theme(axis.ticks.length=unit(-0.25, "cm"), axis.ticks.margin=unit(0.5, "cm"))
如上例所示,您还需要使用
axis.ticks.margin
来调整刻度标签的位置。请注意,该值应作为
unit
对象传递,这要求加载grid
包(预装有R)。
关于r - 如何在ggplot2中使轴刻度线朝内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26367296/