0
votes

I want to make this code using qplot into code using ggplot:

qplot(tuition,data = d0,bins=30, facets = .~ `School Type`)

and this gives the graph style that I want:

Desired plot

however I want to use ggpplot and the code that I tried is:

p <- ggplot(data = d0, aes(x=tuition))
p +geom_histogram()
p +facet_wrap(~`School Type`)

and this give a plot with nothing on the y axis and I'm not sure why:

undesired plot

how can I change my ggplot code to make the plot look like the qplot plot?

1
Just to note: tutorials used to use qplot as a "gateway" to learning ggplot, years ago. But now we would recommend starting with ggplot and learning how that works from the outset. - neilfws

1 Answers

2
votes

Try

p + geom_histogram() + facet_wrap(~`School Type`)

Notice how we are adding both layers to the same object.

With your code

p <- ggplot(data = d0, aes(x=tuition))   # create object
p + geom_histogram()                     # adds histogram, but this is never saved
p + facet_wrap(~`School Type`)           # only adds factets to p, not histogram

line 3 doesn't "remember" that you added a histogram layer in the past (line 2) because you never saved that anywhere.