Nicholas Hayden
Nicholas Hayden

Reputation: 523

Creating a Histogram with Plot Data (ggplot2)

I am a student programmer attempting to plot a histogram.

I have following sample histogram data.

V1  V2
214 6
215 6
216 6
217 5
218 5
219 6
220 5
221 6
222 6
223 6
224 6
225 6
226 6
227 7
228 7
229 7
230 7
231 8
232 8
233 8
234 8
235 8

The first column being what number is repeated and the second is the amount of repeats.

Currently, I am trying ggplot(df, aes(V1, V2)) + geom_bar() and I am not producing a graph.

I am probably overlooking an option. How would you plot this histogram?

Thank you

Upvotes: 0

Views: 322

Answers (2)

Adam
Adam

Reputation: 668

You can use the repeat function in order to get all of the data fleshed out

Data <- rep(V1, each = V2)
hist(Data)

This should do what you want it to and its simple and should be fast

Upvotes: 0

Lowpar
Lowpar

Reputation: 907

Just pass the name of your variable into this code.

 hist(VARIABLE_NAME, 
      main="Histogram of XYZ", 
      xlab="X access", 
      border="blue", 
      col="green",
      xlim=c(100,700),
      las=1, 
      breaks=5)

Upvotes: 1

Related Questions