2017-08-23 8 views
1

フォーク、助けてください。すべてを試しました。さまざまなオプションを使いました。要因として、残念ながら...何も動作、scale_fill_manualとscale_fill_gradientと、なし:(ggplotパレットの問題を修正する - グラデーションボックスプロットを作成するには?

私は

income.boxplot <- ggplot(income.by.state, aes(x = State, y = Estimate)) + 
geom_boxplot() + 
coord_flip() + scale_x_discrete(limits = rev(levels(income$State))) + 
labs(title = "Median household income by state", 
    subtitle = "Source: 2011-2015 American Community Survey") + 
theme(plot.title = element_text(hjust = 0.5)) + 
labs(x = "State", 
    y = "Median household income", 
    fill = "Median household income") + 
theme_fivethirtyeight() + 
theme(axis.line.x = element_line(size = .5, colour = "black"), 
    axis.title = element_text(size = 14), 
    legend.position = "right", 
    legend.direction = "vertical", 
    legend.box = "vertical", 
    legend.key.size = unit(0.7, "cm"), 
    legend.text = element_text(size = 10), 
    text = element_text(family = "OfficinaSanITC-Book"), 
    plot.title = element_text(family = "OfficinaSanITC-Book")) 
income.boxplot 

箱ひげ図を作成したenter image description here

。完璧に見えますが、私はそれのためのパレットを作成することはできません。低所得のオレンジ色のオレンジ色を欲しがり、高/青の色にグラデーションを描いてみたい

いつか私にはがあります。エラー(x = State、y = Estimate):未使用の引数(y = Est iMateの)

私のデータは

1   Ziebach County Median Household Income ($) South Dakota 35119 
2    Zavala County Median Household Income ($)   Texas 26672 
3    Zapata County Median Household Income ($)   Texas 32162 
4    Yuma County Median Household Income ($)  Colorado 43105 

アップデートのように見えます!

私は何かを見つけました。​​ しかし、のcolor = as.integer(Estimate)、group = Estimationでこれを実行しようとしたときに、それが悪くなりました。それで何とか可能です。 enter image description here

更新2!

このPrintScreenを私の望ましい結果を示していますが、これは、私はタブローに慣れていないんだけど、それはそれではない勾配そのもののように見えるのではなく、着色されている点があることをタブロー enter image description here

+1

あなたはggplotのための 'AES()'内側= Estimate'を埋める '含まれていましたか?そうでなければ 'scale_fill_XXX()'関数はどのマッピングを使うべきか分からないでしょう。また、ここでは、状態を要素に変換することは適切ではないと私は考えています。 –

+1

関連性があります:https://stackoverflow.com/questions/42494885/fill-boxplot-color-based-on-value-gradient – www

+0

@ Z.Lin、私はしましたが、それは問題を解決していない伝説を作成しました。 – Oleksiy

答えて

1

です彼らのボックスプロットの4分の1に基づいています。それはできます!

library(dplyr) 
library(ggplot2) 

data_frame(st = rep(state.name[1:5], each = 20), 
      inc = abs(rnorm(5*20))) %>% 
    group_by(st) %>% 
    mutate(bp = cut(inc, c(-Inf, boxplot.stats(inc)$stats, Inf), label = F)) %>% 
    ggplot(aes(st, inc)) + 
    stat_boxplot(outlier.shape = NA, width = .5) + 
    geom_point(aes(fill = factor(bp)), shape = 21, size = 4, alpha = 1) + 
    scale_fill_brewer(type = "div", 
        labels = c("1" = "Lowest outliers", "2" = "1st quartile", 
           "3" = "2nd quartile", "4" = "3rd quartile", 
           "5" = "4th quartile", "6" = "Highest outliers")) 

enter image description here

関連する問題