-1

I am trying to plot all my variables in one go, using ggplot and facet_wrap. However, I am not able to make the code work.

My dataset is a variety of categorial and numeric variables and I want the x-vaiable for all to be the same.

What I have done:

  data %>%
    keep(is.numeric) %>%
    gather() %>%
    ggplot(aes(value))+
    geom_point(~ key)
      facet_wrap(~ key)

I have also tried

The problem is nothing appears, or there is a missing a y-variable...

I hope that someone can help me move forward from this challenge.

BloopFloopy
  • 139
  • 1
  • 2
  • 12

1 Answers1

1

This? Based on OP's request, here is a representative using gapminder. It can be tweaked as desired.

gapminder::gapminder %>%
  gather("id","value",4:ncol(.)) %>%  
  ggplot(aes(continent,value,col=id))+geom_col()+facet_wrap(.~id)+
  theme_minimal()+
  theme(axis.text.x = element_text(angle=90))

Original Answer:

library(tidyverse)
    iris %>% 
    keep(is.numeric) %>% 
      gather() %>% 
      ggplot(aes(value,key))+geom_point()+facet_wrap(key~.)

Sample 2:

iris %>% 
keep(is.numeric) %>% 
  gather() %>% 
  ggplot(aes(key,value))+geom_col()+facet_wrap(.~key)
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 1
    I have a total of 6 varaible: country, continent, year, lifeExp, pop and gdpPercap (gapminder dataset). If i now want to place "continent" as the x-variable for all graphs, then how do I do this? – BloopFloopy Jan 18 '19 at 12:00