I have a ggplot2 theme that I like for facetted plots, but want to add axis tickmarks as described in these threads, but this time for the multipanel case:
- Add axis tick-marks on top and to the right to a ggplot?
- How do I add ticks to the top and right side of a graph in ggplot2
As an example, I include the following code:
## load libraries
library(ggplot2)
library(grid)
library(reshape2)
library(dplyr)
## ggplot settings
theme_update(strip.text=element_text(size=14),
strip.text.x=element_text(vjust=1),
strip.text.y=element_text(vjust=0,angle=90),
strip.background=element_rect(color=NA,fill=NA,
linetype=0),
axis.text=element_text(size=12),
axis.text.y=element_text(angle=90),
axis.ticks.length = unit(-0.3, "lines"),
axis.ticks.margin = unit(0.5, "lines"),
panel.border=element_rect(color=1,fill=NA),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
## transform the iris dataset
iris.long <- melt(add_rownames(iris,"Sample"),id.vars=c("Sample","Species"))
iris.long$Component <- sub("(.+)\\.(.+)","\\1",iris.long$variable)
iris.long$Dimension <- sub("(.+)\\.(.+)","\\2",iris.long$variable)
iris.wide <- dcast(iris.long,Sample+Species+Component~Dimension)
## make the plot
ggplot(iris.wide)+
geom_point(aes(Length,Width))+
facet_grid(Species~Component)
which gives the following figure:
Ticks on the top and right (and also bottom and left for panels that don't have the tick labels) would be an improvement. I am not as familiar with the inner workings with the internals of ggplot/grid graphics - but is this something that can be implemented in a formulaic way? ggplot2::annotation_logticks()
seems to have implemented such a feature, but I cannot use it with linear scale plots.