我正在尝试使用 R Studio 进行数据可视化,需要 X 轴和 Y 轴上的所有点

I am trying a data visualization using R Studio and need all points in X and Y axis

sample image pic

我是 R 编程的新手,正在尝试使用 ggplot2 进行简单的数据可视化。我正在尝试在 X 轴上显示 Airbnb 酒店的夜间价格分布。 'Price' 在 X 轴上,我试图在该列中显示所有价格(而不仅仅是 0,100,200,300),例如 0,10,20,30,.....有人可以帮忙吗。

看看 tidyverse R 包,尤其是 dplyr 和 ggplot2:

library(tidyverse)

# create example data
set.seed(1337)
prices <- tibble(
  id = seq(100),
  price = rnorm(mean = 100, sd = 50, 100) %>% abs()
)


filtered_prices <- filter(prices, price < 100)
qplot(price, data = filtered_prices, geom = "histogram")
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

qplot(price, data = filtered_prices, geom = "density")

reprex package (v2.0.1)

于 2022-02-08 创建

使用ggplot2,可以使用geom_density,然后显示x-axis沿线的每个10,可以使用scale_x_continuous.

library(ggplot2)

ggplot(df, aes(x=price)) +
  geom_density(alpha=0.4) +
  scale_x_continuous(breaks = seq(0, max(df$price), 10))

输出

数据(感谢@danlooo 提供数据)

df <- structure(list(id = 1:100, price = c(109.624595324253, 27.6649096833247, 
                                           83.8409732976183, 181.114805826247, 65.5487938201821, 202.106111130748, 
                                           147.188955595147, 204.096343939955, 195.855863939165, 79.2593880203536, 
                                           151.642674971707, 16.0715203902367, 107.877484517272, 174.456805822279, 
                                           96.210521872544, 163.589047207947, 132.083670383609, 140.038062746858, 
                                           193.132961283141, 72.7321986615563, 130.963890537559, 106.132021275504, 
                                           60.4507917286959, 75.0114164907217, 18.2423993103795, 189.228365966262, 
                                           114.943913606508, 137.625244706715, 46.2698928281852, 103.213687214262, 
                                           163.132473955447, 154.997464810468, 43.8222435603852, 272.303942631828, 
                                           64.0138914012169, 83.6572951230969, 73.5113015030196, 126.207637222461, 
                                           46.0195176447721, 97.244449039937, 209.934209220287, 11.3045335692197, 
                                           103.251611324842, 132.748519111359, 64.3565445507629, 151.028376981832, 
                                           131.580735955202, 122.371667635779, 123.326853205371, 65.0869696099348, 
                                           98.1772722505436, 155.898308483086, 64.9958736705616, 43.7975911576335, 
                                           69.3466360115026, 150.62213539352, 17.193508112824, 129.513154538279, 
                                           115.956716797703, 135.080322322307, 31.1271434940532, 115.632293916597, 
                                           156.042378896312, 123.591544480071, 156.384266079119, 133.88615684784, 
                                           175.511995898008, 203.051717486004, 67.4842044143933, 33.7881163386762, 
                                           132.973565300411, 88.9287426485258, 51.8920445993446, 109.373009595098, 
                                           100.612231498194, 135.614186933111, 62.3137096206145, 101.909496555451, 
                                           158.921053166486, 92.3398075387043, 91.9151233455572, 173.013105599786, 
                                           200.472921822109, 96.1030891096855, 167.717103863236, 48.6408103817855, 
                                           47.9412339814337, 56.4688492407377, 142.656510914191, 68.861990329901, 
                                           160.785493322116, 18.9295625344691, 96.5712335603303, 96.8508537720102, 
                                           153.785385539535, 156.455037629072, 122.507336310327, 102.529322114613, 
                                           93.7834890773161, 145.600572946958)), class = c("tbl_df", "tbl", 
                                                                                           "data.frame"), row.names = c(NA, -100L))