如何删除r编辑

时间:2018-01-18 11:20:19

标签: r ggplot2 position bar-chart axis

我正在使用ggplot2来创建分组条形图。到目前为止很开心。我唯一的问题是条和x轴之间的空间。任何人都可以帮我如何删除它,使x轴与y轴在0处相交?这是我到目前为止的代码

library(ggplot2)

#this creates the table for the data used in the figure, i can't use spaces in the names or it won't work
data <- read.table(text="
predator,juvenile,frequency
uninfected,uninfected,20
uninfected,infected,10
infected,uninfected,16
infected,infected,14", header=TRUE, sep=",")

data

#this changes the order in which the bars are plotted in the figure
data$predator<-factor(data$predator,levels=c("uninfected","infected"))


#this plots the barchart
p<-ggplot(data, aes(x=predator, y=frequency, fill=juvenile)) +
geom_bar(stat="identity",colour="black", position="dodge")+
scale_fill_manual(values = c("#FFFFFF", "#000000"))

p

# this changes the axis lables on the plot and sets up the look of the figure
p+ theme(legend.position = "none",panel.grid.major = element_blank(),           panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour =   "black"))+labs(x="adult",y="frequency of choice") 

任何帮助都会很棒。感谢

修改。我确实尝试了比例连续命令,但它删除了y轴线,我无法回来。任何帮助,请

enter image description here

0 个答案:

没有答案