R语言绘图:直方图

时间:2023-03-09 17:06:41
R语言绘图:直方图

使用ggplot2包绘制直方图

######*****绘制直方图代码*****#######
data1 <- data0[(data0[, 2] <= 500) & (data0[, 4] <= 150000), ]
#提取面积500以下且单价十五万以下的观测
ggplot(data1, aes(x = price)) + #选取单价作为横轴
geom_histogram(bins = 30, fill = "grey60") + #画直方图
labs(x = "价格", y = "频数", title = "北京二手房价格直方图") #添加标题