In a number of instances, I've needed to make minor changes to ggplot output using methods that aren't provided by ggplot parameters themselves. The example below is a good demonstration:
When applying geom_text with position = ggplot2::position_stack() you can't nudge the text left or right. Code is here.
I have limited experience with the grid package and grobs, but my understanding is that I should be able to search the results of grobTree(), find a specific grob, and edit it. In the example above, I'd like to find the "Segment X" text and move it all to the left.
Is this possible and can anyone provide any code related to searching for specific elements and modifying them?
Hi, not a grid solution but it may work with a trick as well. You could try to add a third group on the x-axis to plot the segement labels and only show two labels as axis text. Or, vice versa, turn the x-axis into numeric and place the text labels at e.g. 0.5 with the stacked bars sitting at 1 and 2.
Hi @Adam_Ribaudo,
I note that a ggplot2 object is NOT a grob but can be converted to one, which may help your editing ambitions. However, I think @Z3tt has the right approach = put the Segment texts in the correct position on the LHS using ggplot itself.
Thanks. I found a way to move the segment text, but I'm still interested in converting my ggplots to grobs for advanced editing purpose. I think @DavoWW 's mtcars example is a good one. To make a very simple change, here's how I can change the background color of the plot.
But beyond this, I'm at a loss as to how I would search for a specific element and edit it.