Trying to move axis labels further from axis: formal argument "axis.title.x" matched by multiple actual arguments

Hello all,

I am trying to plot a graph:

g2 <- ggplot(Videogamefrequency, mapping=aes(x = Videogamefrequency, y = Cummulativescore, color =as.character(Trialtype), shape = as.character(Trialtype))) + geom_point(shape=16)+ geom_point(data=Videogamefrequencygroup,shape=19,size = 4,mapping=aes(x=Videogamefrequency, y=Cummulativescore)) + geom_line(data=Videogamefrequencygroup,aes(group=Trialtype),size=2) + geom_errorbar(data= Videogamefrequencygroup,mapping=aes(x=Videogamefrequency, ymin=Cummulativescore-SE,ymax=Cummulativescore+SE)) + theme_bw() + guides(color = guide_legend("Trial Type"), shape = guide_legend("Trial Type")) + labs(x = "Frequency of video game use", y = "Cummulative Score") + theme(axis.title.x = element_text(size=14, face="bold"), axis.title.y = element_text(size=14, face="bold"),legend.text=element_text(size=14),title=element_text(size=14,face="bold"), plot.title = element_text(hjust = 0.5), legend.title = element_text(size=14,face="bold"), axis.text.x=element_text(size=14),axis.text.y=element_text(size=14),axis.title.y=element_text(hjust=1), axis.title.x=element_text(vjust=1)) + scale_colour_brewer(palette="Dark2")

However, I keep getting this error:


Error in theme(axis.title.x = element_text(size = 14, face = "bold"),  : 
  formal argument "axis.title.x" matched by multiple actual arguments

Would anyone be willing to give a helping hand?

Hi @eyavuz21,

In this case, the error message is very informative. You have provided the argument axis.title.x twice in your code, meanwhile it can only match once when calling the theme() function. So you need to remove one of the axis.title.x specifications and combine them into one. For example:

# Produces error, won't run
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  theme(
    axis.title.x = element_text(size = 14, face = "bold"), 
    axis.title.x = element_text(vjust = 1)
    )

# Works as expected
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  theme(
    axis.title.x = element_text(size = 14, face = "bold", vjust = 1)
  )
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.