Not getting a plot

I recently got a new computer so I installed R and R studio to my computer. I believe I chose to install the Berkley R 3.53 package. (maybe that helps)

The code I ran was the following:

library(tidyverse)
library(ggmap)
library(ggplot)

college <- read_csv('http://672258.youcanlearnit.net/college.csv')
college <- college %>%
  mutate(state=as.factor(state), region=as.factor(region),
         highest_degree=as.factor(highest_degree),
         control=as.factor(control), gender=as.factor(gender),
         loan_default_rate=as.numeric(loan_default_rate))


states <- map_data("state")

states

Why am I not getting a graph? The graph I should be getting is in the "plot" box in R in the following link: https://imgur.com/FXg58g1

Hi Jay, welcome!

You are not getting a plot because in the code you are showing you are plotting nothing, you have missed the last part.

library(tidyverse)
library(ggmap)

college <- read_csv('http://672258.youcanlearnit.net/college.csv')
college <- college %>%
    mutate(state=as.factor(state), region=as.factor(region),
           highest_degree=as.factor(highest_degree),
           control=as.factor(control), gender=as.factor(gender),
           loan_default_rate=as.numeric(loan_default_rate))

states <- map_data("state")

# You are missing this part
ggplot(states) +
    geom_polygon(aes(x = long, y = lat, group = group), color = "grey", fill = "beige") +
    coord_map() + 
    theme(plot.background = element_blank(),
          panel.background = element_blank(),
          axis.title = element_blank(),
          axis.ticks = element_blank(),
          axis.text = element_blank())

Created on 2019-04-22 by the reprex package (v0.2.1)

Thanks for welcoming me.

What do you mean that I didn't run the last part ?

The code you have posted doesn't include the plotting part that is shown in your screen shot, i.e. this code

ggplot(states) +
    geom_polygon(aes(x = long, y = lat, group = group), color = "grey", fill = "beige") +
    coord_map() + 
    theme(plot.background = element_blank(),
          panel.background = element_blank(),
          axis.title = element_blank(),
          axis.ticks = element_blank(),
          axis.text = element_blank())

It has been fixed. I restarted my computer and it works...weird. Thanks for helping me. Have a wonderful week.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.