I read this answer : How to control number of minor grid lines in ggplot2?
Although I couldn't figure out a way to reconcile it with my requirements.
I want there to be a way to input the number of minor gridlines between two major ticks. (or the ratio of the minor to major grid size) Say I want to divide it into 5 parts (4 minor gridlines). How do I do that?
Since there will be many graphs, of which I wouldn't know the axis limits, I can't explicitly define the size of one minor gridline step. I want to use whatever algo ggplot2 uses to pick the number of major gridlines, and just have 4 times as many minor ones.
I'd like the r graph on the right to look like the excel graph on the left
CODE (in case that helps solve the issue)
ggtheme <- theme(axis.line = element_line(size = 0.5, colour = "black"),
panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour="grey90",size = rel(0.5)),
panel.grid.minor = element_line(colour="grey95",size = rel(0.25)));
ggp_sctr2 = ggplot( sub2_ac_data, aes(x=(sub2_ac_data[,i]),
y=sub2_ac_data[, rescol], colour = factor(sub2_ac_data[,topfac[1]]),
shape = factor(sub2_ac_data[,topfac[1]]) )) + geom_point(size = 2.5) +
scale_shape_manual(values=symlist[Nmsn_sub1+1:20]) +
scale_colour_manual(values = unname(cols[Nmsn_sub1+1:16])) +
geom_smooth(method="lm", formula = y ~ splines::bs(x, 3),
linetype = "solid", size = 0.25,fill = NA )
print(ggp_sctr2 + ggtitle( paste(scxnam[1],nomvar,
"vs",colnames(sub2_ac_data[i]),i, sep = " ")) +
theme(axis.text.x=element_text(angle = 90, hjust = 1,vjust = 0.5,size=8)) +
labs(x = colnames(sub2_ac_data[i]), y=colnames(sub2_ac_data[rescol]),
colour=colnames(sub2_ac_data[topfac[1]]),
shape=colnames(sub2_ac_data[topfac[1]])) + ggtheme +
theme(plot.title = element_text(face = "bold", size = 16,hjust = 0.5))) ;
r
tag description, with the desired output. You can usedput()
,reprex::reprex()
or built-in data sets for reproducible data. – Hack-Rminor.breaks
? If you did, what happened? – aosmith