ImageDimPlot seems not friendly to programmers. I was about to draw area of interests to the spatial images, but I find the way ImageDimPlot and SingleImagePlot use ggplot2 makes my work of annotation very frustrating and my scripts very confusing.
Here is an example showing the problems:
1) The raw image is up-side-down of the raw spatial coordinates as visualized by ggplot2.
2) Adding a vertical line using geom_vline will draw a horizontal line.
The first issue is not surprising, because the imaging data (seems always) has the reversed y-axis. Reversing ggplot2's y-axis can quickly solve the problem. What bothers me is the second issue. Because to visualize the correct ROIs, I need to feed the real x to y and feed the real y to x. In this case, if I want to draw a vertical line, I need using geom_hline -- making my codes very confusing to others.
This problem is applicable to other spatial-related visualization functions.
Why
It is because SingleImagePlot firstly always feed the real x to y and the real y to x. See source code here:
Though the end-result of visualization is right, it leads to very frustrating effect on following annotations -- I will have to feed the real x to y and the real y to x.
Example to show the idea
# insert reproducible example here
iris$raw_x <- iris$Sepal.Length
iris$raw_y <- iris$Petal.Length
ggplot(iris, aes(x=raw_x, y=raw_y)) +
geom_point() +
geom_vline(xintercept =5, color='red') +
labs(title='correct and wanted annotation')
# Mimics the implementation of flip_xy=FALSE
# It gives the correct result
ggplot(iris, aes(y=raw_x, x=raw_y)) +
geom_point() +
coord_flip() +
labs(title='Mimics the implemention of flip_xy=FALSE')
# However, it leads to confusing and frustrating further annotations
ggplot(iris, aes(y=raw_x, x=raw_y)) +
geom_point() +
coord_flip() +
geom_vline(xintercept =5, color='red')+
labs(title='wrong annotation because of the complexed implementation')
Possible solution
[optional] Reverse the y-axis when using ggplot. This will achieve the same in situ visualization.
Feed the real x to x and the real y to y.
ggplot(iris, aes(x=raw_x, y=raw_y)) +
geom_point() +
scale_y_reverse() +
geom_vline(xintercept =5, color='red') +
labs(title='repeat the in situ visulization and wanted annotation')
Problem
ImageDimPlot seems not friendly to programmers. I was about to draw area of interests to the spatial images, but I find the way
ImageDimPlot
andSingleImagePlot
use ggplot2 makes my work of annotation very frustrating and my scripts very confusing.Here is an example showing the problems: 1) The raw image is up-side-down of the raw spatial coordinates as visualized by ggplot2. 2) Adding a vertical line using
geom_vline
will draw a horizontal line.The first issue is not surprising, because the imaging data (seems always) has the reversed y-axis. Reversing ggplot2's y-axis can quickly solve the problem. What bothers me is the second issue. Because to visualize the correct ROIs, I need to feed the real x to
y
and feed the real y tox
. In this case, if I want to draw a vertical line, I need usinggeom_hline
-- making my codes very confusing to others.This problem is applicable to other spatial-related visualization functions.
Why
It is because
SingleImagePlot
firstly always feed the real x toy
and the real y tox
. See source code here:https://github.com/satijalab/seurat/blob/1549dcb3075eaeac01c925c4b4bb73c73450fc50/R/visualization.R#L8780-L8788
Then, to achieve the effect of
flip_xy=FALSE
, the following lines have to 'ad-hoc' fix the problem by doingcoord_flip()
; this is confusing to programmers. https://github.com/satijalab/seurat/blob/1549dcb3075eaeac01c925c4b4bb73c73450fc50/R/visualization.R#L2587-L2590Though the end-result of visualization is right, it leads to very frustrating effect on following annotations -- I will have to feed the real x to
y
and the real y tox
.Example to show the idea
Possible solution
x
and the real y toy
.