Segmentation Tutorial part 8 - veeninglab/BactMAP GitHub Wiki

Extra’s

On plotting

There is a lot you can do outside of BactMAP to make a plot look nice. I just show a few options below, but check the ggplot2 vignette to get a good overview of what is possible!

Within BactMAP, I saved a few palettes for the use in heatmaps or for categorical values. colorsCUD() gives you back a list of the CUD colorblind-friendly palette. Furthermore, BactMAP uses the viridis color scales a lot as standard heatmaps.

When it comes to plotting distributions, the following 'geoms' (especially combined) are good to check out:

Finally, there is a whole range of themes you can choose from. I mostly use theme_minimal() and theme_classic(). Noteworthy is also theme_void(), which removes all lines and text for you.

Some examples:

width <- ggplot(onePerCell, aes(x=condition, y=maxwum)) +
  geom_jitter(alpha=0.3, size=0.2) +
  stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom="crossbar") +
  theme_classic() +
  ylab("cell width (micron)") +
  ggtitle("Cell width distribution per segmentation")

area <- ggplot(onePerCell, aes(x=condition, y=area)) +
  geom_violin(draw_quantiles=(c(.25, .5, .75)), size=1, aes(fill=condition)) +
  scale_fill_manual(values=bactMAP::colorsCUD()) +
  theme_light() +
  ylab("Cell area (pixel*pixel)") +
  ggtitle("Cell area distribution per segmentation") +
  theme(legend.position="none")

gridExtra::grid.arrange(width, area, ncol=1)

More descriptive statistics

If you want to summarize your data, it can also be handy to use aggregate() or descr().

aggregate() takes data you put in front of the function, and calculates your given FUN (in this case the median) by whatever you put in “by”:

medianPerCondition <- aggregate(onePerCell[,c("max_um", "maxwum", "area")], by=list("condition"=onePerCell$condition), FUN=median)

medianPerCondition
##              condition   max_um    maxwum     area
## 1        Clement_Oufti 2.122123 0.8750139 560.6055
## 2            Jun_Oufti 1.889762 0.8361367 475.5984
## 3      Jun_SuperSegger 1.879283 0.6799276 383.6188
## 4       Lance_MicrobeJ 1.458337 0.7064676 305.3750
## 5 Renske_Morphometrics 1.446555 0.7859416 393.4439

If you use descr() (a function from summarytools) together with with, you can do something very similar: describe a given variable (here: max_um) by another given variable (here: condition):

descriptionMax_um <- with(onePerCell,
                          by(max_um, condition, summarytools::descr))
summarytools::view(descriptionMax_um)


⬅️ Segmentation Tutorial part 7: Statistical Tests Segmentation Tutorial part 9: Resources ➡️
⚠️ **GitHub.com Fallback** ⚠️