Saturday, 15 January 2011

ggplot2 - Is it possible to use free_y in likert plots from likert r package? -



ggplot2 - Is it possible to use free_y in likert plots from likert r package? -

i making nice plots using likert package. problem encounter haven't been able create heights of plots depend on number of likert scales.

if have 1 likert scale result ugly. want abley influence height.

plot(likert(likert_5),type="heat",text.size=2.5)

this result:

and want this:

i tried facet_grid() function of ggplot2 package, didn't work.

plot(likert(likert_5),type="heat",text.size=2.5)+facet_grid(scales = "free_y", drop = false)

i must admit new ggplot2 (and bundle likert depends on ggplot2), solution turn out simple, help me lot! many in advance.

here's reproducable example:

df <- structure(list(variable = c(1, 2, 3, 4, 2, 3, 1, 5, 3, 4, 2, 1, 1, 1, 4, 5)), .names = "variable", row.names = c(na, -16l), class = "data.frame") df[,1] <- factor(df[,1], levels=c(1,2,3,4,5)) library(likert) plot(likert(df),type="heat",text.size=2.5)

this depends on how you're using plot. in interactive r session, best bet resize plotting window. don't know how resize plot window programmatically in rstudio. if you're not using rstudio you should start using it! can give height , width dev.new(), e.g.,

dev.new(height = 1, width = 5) plot(likert(df),type="heat",text.size=2.5)

if you're saving plot, whatever method you're using has height , width arguments, , programmatic approach makes sense. e.g.,

lplot <- plot(likert(df),type="heat",text.size=2.5) ggsave("myplot.png", plot = lplot, width = 5, height = 1)

if want modify plot object itself, can edit class of coordinate attribute of plot.

lplot <- plot(likert(df),type="heat",text.size=2.5) lplot <- lplot + coord_fixed() # default ratio of 1 looks me # can adjust class(lplot$coordinates) <- c("flip", class(lplot$coordinates)) print(lplot)

r ggplot2

No comments:

Post a Comment