开发者

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 histog开发者_运维问答ram?


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")

How to plot histogram of x and y values?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜