当前位置: 动力学知识库 > 问答 > 编程问答 >

r - How to plot histogram of x and y values?

问题描述:

Today I want to learn a little bit about the R statistical programming language.

I'm not finding the tutorials to be helpful yet.

I hope to jumpstart this effort with a simple task.

I have 3 x values: 1.5, 2.5, 3.5

and 3 y values: 1.2, 0.1, 4.4

I want to plot a histogram with this data.

q1: What is the least amount of R syntax I can use to plot this historgram?

q2: Can I put the data in myfile.csv and ask R to read myfile.csv and then plot the histogram?

网友答案:
dat <- data.frame(x=c(1.5, 2.5, 3.5), y=c(1.2, 0.1, 4.4))
barplot(dat$y, names.arg=dat$x, ylim=c(0,5))

That will do what you're after. I think. Labels can be added like so.

barplot(dat$y, names.arg=dat$x, ylim=c(0,5), ylab="blah", xlab="lol")

A histogram has bars touching (continuous x variable), and bar chart/plot doesn't, strictly speaking, so this may not be what you're after...

网友答案:

Er, do you mean a scatter-plot, or a three-dimensional histogram with (x,y) pairs of (1.5,1.2), (2.5,0.1), and (3.5,4.4)? If the former, just use plot(x,y) to get the scatterplot, use write to output the data to file, and use read.csv to read the data from a csv file.

分享给朋友:
您可能感兴趣的文章:
随机阅读: