0

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

3
  • Bar chart would great but I get the errors. 'Error: Unknown parameters: binwidth, bins, origin, right' Commented Jul 14, 2016 at 20:28
  • 1
    ggplot(df, aes(V1, V2)) + geom_bar(stat = "identity") Commented Jul 14, 2016 at 20:30
  • With geom_bar(), could you do a pseudo bin? Commented Jul 14, 2016 at 20:31

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

8 Comments

I am using a data frame with two variables. I am trying to make it with two vectors
I was wondering about that, I thought that the first vector was the row number because it descends in value. Do you have the prior code? I think where you have aes it should be factor and you should have 1 - ggplot(df, aes(x = factor(V1))) + geom_bar(stat = "bin")
what about ggplot(df, aes(x=(V1), y=V2)) + geom_bar(stat = "identity")
I think that might have to do with breaks.
+ scale_y_continuous(breaks = seq(0, 100, by = 20)) see - stackoverflow.com/questions/22818899/… it gives a great presentation on how ggplots works.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.