2

I am working on a research project and I am trying to show my boss some clean graphs that can be put into a project. I made this sieve plot and I can't figure out 1. How to rotate the x-axis labels and make pull them off the graph and 2. How to move up the y-axis labels that are overlapping the top of the graph as well.

I have tried to rotate the labels and it still overlaps the graph.

library(vcd)
library(vcdExtra)
All <- matrix(c(924,139,67,42, 115,66,61,22, 40,37,51,45, 33,19,30,57), 4, 4)
dimnames(All) <- list(Drinking2002 =c("Rare","Light","Moderate","Heavy"), Drinking2014 =c("Rare","Light","Moderate","Heavy"))
All <- as.table(All)
sieve(All, shade = TRUE, labeling = labeling_values, gp_text = gpar(fontface = 2), rot_labels = c(top = 45))

Thank you for your help!

Sam Cole
  • 57
  • 6

2 Answers2

2

1) rot_labels = c(left = #, top = #) to rotate labels 2) `offset_labels = c(#, #, #, #) to adjust the distance from the axis.

sieve(All, shade = TRUE, labeling = labeling_values, 
      gp_text = gpar(fontface = 2), 
      rot_labels = c(top = 45, left = 0), 
      offset_labels = c(0.6, 0, 0, 1)
      )

enter image description here

Or

sieve(All, shade = TRUE, labeling = labeling_values, 
      gp_text = gpar(fontface = 2), 
      rot_labels = c(top = 0, left = 0), 
      offset_labels = c(0.6, 0, 0, 1)
      )

enter image description here

Zhiqiang Wang
  • 6,206
  • 2
  • 13
  • 27
  • Is there a way to move the axis titles up, Like the Drinking2014? On my markdown I keep having troubles with rare hitting the Drinking2014 label – Sam Cole Oct 09 '19 at 04:36
  • yes, try `offset_varnames = c(0.5, 0, 0, 0.5)`. Adjust values to see if it is possible to fit your markdown. – Zhiqiang Wang Oct 09 '19 at 05:22
  • Just think of alternatives. If variable names keep causing troubles, you could try to move them inside: `offset_varnames = c(-3, 0, 0, -3)`, or even remove them completely: `varnames = FALSE`, and explain them in the title or elsewhere. – Zhiqiang Wang Oct 09 '19 at 06:01
1

Extending based on the answer provided here for mosaic plot.

sieve(All, shade = TRUE, 
     labeling = labeling_border(rot_labels = c(30,0,0,30),just_labels = c("left","right","right","right")), 
     gp_text = gpar(fontface = 2), 
     rot_labels = c(top = 45))

You can play around with c(30,0,0,30) to change the degree of rotation and with c("left","right","right","right") for label alignment. Hope this helps.

EDIT: Added screenshots

Output 1:

Using just_labels = c("left","right","right","right") enter image description here

Output 2:

Using just_labels = c("left","right","right","left")

enter image description here

FAlonso
  • 494
  • 2
  • 15