I'm trying to plot my data with ggplot2 but the data from my x-axis should be log transformed. I tried using the function coord_trans because I want to keep the original labels and just transform my coordinates but when I do this, all my points disappear from my graph. I have no idea why this is happening? Could it be because there are zero's in my data? And how can I fix this?
Here is my input for making the ggplot:
library(afex)
library(car)
library(MASS)
library(rockchalk)
library(multcomp)
library(lsmeans)
library(gplots)
library(ggplot2)
library(tidyr)
library(effects)
library(scales)
library(ggthemes)
library(gtools)
theme_set(theme_few(base_size=14))
p=ggplot(data, aes(x=day, y=(propinfected), linetype=treatment, group=treatment)
p + geom_smooth(aes(fill=treatment),colour="black", method="glm",
family="quasibinomial")+
coord_trans(xtrans = "log10")+
geom_point(aes(fill=treatment),size=5,pch=21)+
labs(x="Day", y="Above detection treshold", size=10)+
scale_y_continuous(labels= percent,breaks=seq(0,1,by=0.2),limits=c(0,1))+
scale_x_continuous(breaks=seq(0,16,by=4),limits=c(0,16))+
scale_fill_manual(values=c("black","grey"))+
theme(legend.justification=c(1,0), legend.position=c(1,0),
legend.title=element_blank(),axis.text=element_text(size=20),
axis.title=element_text(size=20),legend.text=element_text(size=15))
This is the model I work with:
fitlog=glm(propinfected~log10(day+1)*treatment,family=quasibinomial(link=logit), data=data)
This is the data I used:
dput(data)
structure(list(treatment = structure(c(1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L), .Label = c("CTRL", "DWV"), class = "factor"),
day = c(0L, 0L, 4L, 4L, 8L, 8L, 12L, 12L, 16L, 16L), infected = c(0L,
20L, 11L, 20L, 15L, 18L, 16L, 19L, 19L, 19L), not_infected = c(20L,
0L, 9L, 0L, 5L, 2L, 4L, 1L, 1L, 1L), propinfected = c(0,
1, 0.55, 1, 0.75, 0.9, 0.8, 0.95, 0.95, 0.95)), .Names = c("treatment",
"day", "infected", "not_infected", "propinfected"), row.names = c(NA,
-10L), class = "data.frame")
When I plot my graph with the allEffects function, I get the correct plot, with correct lines and confidence bands. But I want to do it in ggplot because the allEffects plot is not so pretty.
plot(allEffects(fitlog),ylab="Above detection treshold",type="response")
Thanks for helping!