When I save a graph from R using ggplot2 and geom_col() or geom_bar(stat = 'identity') it comes out with some unsightly horizontal white lines.
Data looks like this:
> head(mouse_track_data)
session site BM.pile ox.pile type mice skinks geckos
1 dec_2018 1 1 1.10 control FALSE TRUE FALSE
2 dec_2018 1 2 1.12 design1 FALSE FALSE FALSE
3 dec_2018 1 3 1.11 control FALSE FALSE FALSE
4 dec_2018 1 4 1.80 control FALSE FALSE FALSE
5 dec_2018 1 5 1.60 design1 FALSE FALSE FALSE
6 dec_2018 1 6 1.50 control FALSE FALSE FALSE
Here's my code:
ggplot(data = mouse_track_data, aes(x = session, y = as.numeric(mice), fill = type)) +
geom_bar(stat='identity') +
theme_classic() +
theme(text = element_text(size=15),
axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Tracking session") +
ylab("Number of tunnels with mouse tracks") +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 7, b = 0, l = 0))) +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 7, b = 0, l = 0))) +
theme(legend.title = element_blank(), legend.position = c(-2, -2)) +
scale_fill_manual(values = c("control" = "#37a1c1", "design1" = "#9ce2cb", "design2" = "#445a9c"),
labels = c(" Control", " Single grade", " Mixed grade")) +
scale_x_discrete(labels = c('Dec 2019', "April 2019", "Nov 2019", "March 2020")) +
scale_y_continuous(breaks=seq(0, 50, 10), limits = c(0,52), expand = c(0,0)) +
theme(axis.line = element_blank())
With this, or using geom_col(), when exporting as ESP or PDF, I get a figure that looks like this:
With fine white lines going accross all the columns. I assume this is something to do with it counting each data point and then piling them up?
If I do the code with geom_bar() it doesn't have white lines but it doesn't show the data how I want it.


