-1

For better visualization, I need to move the strip text of the facets to be on top of each facet.

Now they are on the right side, but I need them on top.

enter image description here

This is my code:

tvs.rangos <- ggplot(tvs , aes(rangos))
tvs.rangos + geom_histogram(aes(fill = marca), width = .7) + labs(title = "Marcas de TV por rangos de precios",
                                                                x = "rango de precios", y = "cantidad de tvs")  +
        facet_grid(ecommerce ~ .) +
        scale_fill_brewer(palette="Set3") +
        theme(axis.text.x = element_text(colour="grey10",size=16,hjust=.5,vjust=.5,face="bold"),
              axis.text.y = element_text(colour="grey10",size=18,,hjust=1,vjust=0,face="plain"),  
              axis.title.x = element_text(colour="grey40",size=12,angle=0,hjust=.5,vjust=0,face="plain"),
              axis.title.y = element_text(colour="grey40",size=12,angle=90,hjust=.5,vjust=.5,face="plain"),
              plot.title = element_text(size = 16,vjust=2),
              legend.title = element_text(colour="grey40", size=16, face="bold"),
              legend.text = element_text(colour="grey10", size=16, face="bold"),
              strip.text.y = element_text(size = 20, angle = 0))

I've found this topic:

ggplot2: Using gtable to move strip labels to top of panel for facet_grid

But, I'm looking for a simplier approach, if any.

Community
  • 1
  • 1
Omar Gonzales
  • 3,806
  • 10
  • 56
  • 120
  • Can you provide the data (your object tvs.rangos) so that it is easier for people to help? – tagoma Dec 27 '15 at 16:45
  • Maybe you can try using `coord_flip` and `scale_x_reverse` like they did here: http://stackoverflow.com/questions/29504883/ggplot2-how-to-swap-y-axis-and-right-facet-strip-and-how-to-order-facet-values – tagoma Dec 27 '15 at 16:49

1 Answers1

1

if you are looking for alternative, why not simply use facet_wrap(). The text will be on top of each facet. I don't have access to your dataset but here is a simple example

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point() + facet_wrap(~Species, nrow=3)

enter image description here

MLavoie
  • 9,671
  • 41
  • 36
  • 56
  • thanks. May you explain why my "facet_grid" approach was wrong? When to use "facet_wrap" and when "facet_grid"? thanks. – Omar Gonzales Dec 27 '15 at 16:52
  • your were not wrong but you were just looking for something different :-) One is on the top, the other on the side! and thanks for accepting the answer! – MLavoie Dec 27 '15 at 16:59