如何使用scale()创建的间隔的scale_x_discrete

时间:2018-03-20 22:55:43

标签: r ggplot2

鉴于此:

kc$sqft_living_group <- cut(kc$sqft_living, breaks = c(0, 1000, 2000, 3000, 5000, 7000, 10000, 15000), dig.lab=5)

如何设置ggplot2图表的限制?

我找不到任何可以显示设置间隔限制的语法。

kc %>%
  filter(zipcode %in% top_10_zipcodes) %>% 
  group_by(sqft_living_group) %>%
  summarize(Mean_Price = mean(price)) %>%
  ggplot(aes(y = Mean_Price, x = sqft_living_group)) +
    geom_bar(stat = "identity") +
    scale_y_continuous(labels = comma) +
    scale_x_discrete(limits = "(0, 1000], (1000, 12000]") <---------- HERE

数据结构:

'data.frame':   21613 obs. of  22 variables:
 $ id               : num  7.13e+09 6.41e+09 5.63e+09 2.49e+09 1.95e+09 ...
 $ date             : POSIXct, format: "2014-10-13" "2014-12-09" "2015-02-25" "2014-12-09" ...
 $ price            : num  221900 538000 180000 604000 510000 ...
 $ bedrooms         : int  3 3 2 4 3 4 3 3 3 3 ...
 $ bathrooms        : num  1 2.25 1 3 2 4.5 2.25 1.5 1 2.5 ...
 $ sqft_living      : int  1180 2570 770 1960 1680 5420 1715 1060 1780 1890 ...
 $ sqft_lot         : int  5650 7242 10000 5000 8080 101930 6819 9711 7470 6560 ...
 $ floors           : Factor w/ 6 levels "1","1.5","2",..: 1 3 1 1 1 1 3 1 1 3 ...
 $ waterfront       : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ view             : int  0 0 0 0 0 0 0 0 0 0 ...
 $ condition        : int  3 3 3 5 3 3 3 3 3 3 ...
 $ grade            : int  7 7 6 7 8 11 7 7 7 7 ...
 $ sqft_above       : int  1180 2170 770 1050 1680 3890 1715 1060 1050 1890 ...
 $ sqft_basement    : int  0 400 0 910 0 1530 0 0 730 0 ...
 $ yr_built         : int  1955 1951 1933 1965 1987 2001 1995 1963 1960 2003 ...
 $ yr_renovated     : Factor w/ 70 levels "0","1934","1940",..: 1 46 1 1 1 1 1 1 1 1 ...
 $ zipcode          : Factor w/ 70 levels "98001","98002",..: 67 56 17 59 38 30 3 69 61 24 ...
 $ lat              : num  47.5 47.7 47.7 47.5 47.6 ...
 $ long             : num  -122 -122 -122 -122 -122 ...
 $ sqft_living15    : int  1340 1690 2720 1360 1800 4760 2238 1650 1780 2390 ...
 $ sqft_lot15       : int  5650 7639 8062 5000 7503 101930 6819 9711 8113 7570 ...
 $ sqft_living_group: Factor w/ 7 levels "(0,1000]","(1000,2000]",..: 2 3 1 2 2 5 2 2 2 2 ...

0 个答案:

没有答案