I made a figure with the following code, however, I recently noticed some of my data points did not contain error bars as they should, so I am revisiting this code a few months after writing it. In this time there has been an update to ggplot2 and now I get errors in my code that I do not know how to fix. These are detailed below.
My code is:
p1 <- ggplot(dat3A, aes(x = d15N, y = Depth))
p4 <- p1 +
geom_point(size = 1) +
geom_path() +
scale_y_continuous(expand = c(0, 0), limits = c(15,0), trans = "reverse") +
scale_x_continuous(expand = c(0, 0), limits = c(0,20)) +
labs(x=expression(paste(delta^'15', N[NO3],('\u2030'))), y='Depth (cm)') +
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_errorbarh(aes(xmax=d15N+d15NError, xmin=d15N-d15NError))+
ggtitle("d") +
theme(plot.title = element_text(hjust = 0, size=8))+
theme(axis.text = element_text(size=6), axis.title=element_text(size=8))
p13 <- ggdraw(switch_axis_position(p4, axis = 'x'))
When I run this all runs okay until I come to the last line of code p13 <- ggdraw(switch_axis_position(p4, axis = 'x'))
Then I get the following errors:
Error in gt$grobs[[ixl]] : attempt to select less than one element In addition: Warning messages: 1:
panel.margin
is deprecated. Please usepanel.spacing
property instead 2: Removed 1 rows containing missing values (geom_errorbarh).
I am not an experienced coder and so I am unsure how to solve these errors. I do not use panel.margin in my code so am not sure how to change this to panel.spacing. If anyone could provide any help on this as well as the gt$grobs[[ixl]]
error I would really appreciate it!