如何在R中使用X和Y轴绘制基本直方图 [英] How to draw a basic histogram with X and Y axis in R

查看:431
本文介绍了如何在R中使用X和Y轴绘制基本直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要制作一个简单的直方图,其中涉及两个向量

I want to make a simple histogram which involves two vectors ,

values <- c(1,2,3,4,5,6,7,8)
freq <- c(4,6,4,4,3,2,1,1)
df <- data.frame(values,freq)

现在data.farame df包含以下值:

values freq
 1    4
 2    6
 3    4
 4    4
 5    3
 6    2
 7    1
 8    1

现在,我想绘制一个简单的直方图,其中value s在x轴上,而freq在y轴上.我正在尝试使用hist函数,但是我不能给出两个变量.如何根据这些数据制作一个简单的直方图?

Now I want to draw a simple histogram, in which values are on the x axis and freq is on y axis. I am trying to use the hist function, but I am not able to give two variables. How can I make a simple histogram from this data?

推荐答案

使用ggplot2:

library(ggplot2)
ggplot(df, aes(x = values, y = freq)) +
       geom_bar(stat="identity")

这篇关于如何在R中使用X和Y轴绘制基本直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆