I am trying to create a plot that has an axis on the top and the right side of the plot. I added minor ticks to the x and y-axis but I noticed that when I try and add a second x and y-axis, the minor ticks are removed. I was also hoping to remove the second axis labels but that doesn't seem to work. I am wondering if there is an issue with how I added the minor ticks?
Do my main questions are, how can I add minor ticks to the second axes and how can I remove the labels.
data.bw <- structure(list(num = c(88L, 58L, 15L, 11L, 14L, 29L, 34L, 40L,
24L, 20L, 3L, 1L, 1L), bar = c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5), group = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor")), class = "data.frame", row.names = c(NA,
-13L))
library(ggplot2)
library(ggh4x)
ggplot(data.bw, aes(bar,num, fill = group)) +
geom_bar(stat = 'identity', width = 1) +
scale_fill_manual(values = c('orange', 'khaki')) +
scale_y_continuous(
minor_breaks = seq(0, 90, by = 2),
breaks = seq(0, 90, by = 10), limits = c(0, 90),
expand = expansion(mult = c(0, 0)),
sec.axis = dup_axis(name = NULL),
guide = "axis_minor"
) +
scale_x_continuous(
minor_breaks = seq(0, 14, by = 0.5),
breaks = seq(0, 14, by = 2), limits = c(0, 14),
expand = expansion(mult = c(0, 0)),
sec.axis = dup_axis(name = NULL),
guide = "axis_minor"
) +
scale_fill_manual(values = alpha(c("red"), .3)) +
theme_bw() +
theme(
panel.border = element_rect(colour = "black", fill=NA, size=1),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)

