DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

Left or right justify text labels in cyto_plot bounding boxes #95

Open rwbaer opened 3 years ago

rwbaer commented 3 years ago

Briefly describe what you hope to achieve: I was trying to use label_text_x to move my labels to the left side of my panels. I had partial success, but I could not figure out how to specify left justification within the label bounding box.

In addition, if I use the zoom feature in RStudio (it didn't seem to be honoring my popup=TRUE) the background of the labels seems to extend disproportionately onto the histograms. I'm not sure whether this is expected behavior or not.

I guess this brings up the corollary question. Is the only way to control the aspect ratio of a cyto_plot() drawing by setting the aspect ratio of interest on the device window ahead of the plot? Do I take it that these dimensions should be the same used in cyto_plot_save() ?

Outline the steps taken to attempt to reach this goal (paste code below):



**Include any associated screenshots or images here:**
![LabelBackgrounds](https://user-images.githubusercontent.com/3155051/99160003-18f4f500-26a8-11eb-9828-eaca1b991a21.png)
DillonHammill commented 3 years ago

@rwbaer, justification of labels is not supported - and it may not be possible given the way in which the labels are added to the plot. You can however, manually position each label to achieve this - just supply an x and y coordinate for each label to label_text_x and label_text_y arguments (e,g, label_text_x = c(1,2,3,4,5,6,7,...).

The label stretching is happening because the label coordinates are fixed and so get stretched when zooming - this is exactly why I wrote cyto_plot_save() to get around this. The best way to do this is still to manually open a popup window with cyto_plot_new(popup = TRUE), adjust the window size as necessary and then make a call to cyto_plot() with popup=FALSE. Lots of refinements to this behavior are coming, hopefully I will get time to release these soon.

rwbaer commented 3 years ago

Just to clarify, when I said "justification" I WAS intending to use label_text_x and label_test_y to position the labels, but text position is specified for the CENTER of the label and not the left edge or right edge. So, apparently it is easy to align on center but not to align on left edge or align on right edge. I think this is done with hjust = 0 for left and hjust =1 for right in ggplot2. So, I guess no similar functionality in cyto_plot() at the moment?

As to the label stretching and its annoying effect on the label backgrounds, I can render this harmless by making use of your "label_fill_alpha = 0" arguement. :-) The cyto_plot_theme_args() command has turned out to be a real help at slowly unpacking the possibilities. They are huge.

rwbaer commented 3 years ago

I think I still have failed to express this clearly with my changed title.

What I hope to be able to specify is to get right or left justification of the text bounding box relative to the specified label_text_x and label_text_y. Perhaps this is the thing that cannot be done, given the implementation.

I just want to be sure that this issue is not taken to mean text justification relative to the graph axes or the graph canvas.

DillonHammill commented 3 years ago

@rwbaer, I know what you are after and I have added it to my (long) list of things to add to CytoExploreR. I am working on revamping the internals of cyto_plot() so I will give this a go when I get to the labels.

rwbaer commented 3 years ago

Great. I was worried I had not communicated well and wanted to make sure I had done so before closing this. I don't know how you like to handle issues, but feel free to close this depending on how you like to handle "issues" and "to do" lists. :-)