2017-11-14 13 views
0

ggplot2で極座標を作成するには次のコードがありますが、他のデータで同じコードを実行すると、同じ縮尺の色値を維持できません。私は、出力プロットは、スケールの値を変更し、異なるデータで同じコードを実行しようとすると、私は多くのことを試してみました、scale_fill_gradientn ggplot2、定数勾配で表現する

plot.new() 
ggplot(NS_Enero, aes(x = wd, y = ws, fill = manganese, size = manganese)) + 
    coord_polar() + 
    geom_point(shape = 21, show.legend = TRUE) + 
    scale_size(range = c(3,12), 
      labels = c("50", "150", "450", "1350", "4050"), 
      breaks = c(50, 150, 450, 1350, 4050), 
      name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) + 
    scale_fill_gradientn(colours = c("darkblue","blue", "yellow", "orange", "red"), 
         space = "Lab", 
         guide = "legend", 
         values = rescale(c(0, 150, 450, 1350, 4401), 
             from = c(0, 4401)), 
         labels = c("50", "150", "450", "1350", "4050"), 
         breaks = c(50, 150, 450, 1350, 4050), 
         name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) + 
    scale_x_continuous(limits= c(0,360), 
        breaks= c(0, 90, 180, 270), 
        labels = c("N","E","S","W"), 
        name = "") + 
    scale_y_continuous(name = "Distance (m)", 
        position = "left") + 
    theme_linedraw() + 
    theme(axis.text.x = element_text(size = 12), 
     axis.text.y = element_text(size = 8)) + 
    ggtitle("     NS_Enero") 

:表現するために3種類の変数があります

は、1配向であります私が他の質問で見つけたヒントはありますが、私はスケール表現の問題を解決できません。

Plot1

出力2(異なるデータ):

Plot 2

私は

出力1 ...問題はscale_fill_gradientnからvaluesであることを考えます最終的な結果は大丈夫ですが、スケールの範囲の値(sizeとco lor)は、私がさまざまなデータ範囲で実行しているすべてのプロットで一定である必要があります。 0〜4050の値の同じサイズと色の値。

ありがとうございました。

+0

たぶん、 '' scale_fill_gradientn'でlimits'を指定しますか? – Roland

+0

オハイオ州の神、それはとてもシンプルでしたが、それは動作します、あなたの助けを大変ありがとう。 – Maka

答えて

1

最後に、limitsを追加しました。

これは、最終的なコードです:

#Tamaño y color 
plot.new() 
ggplot(NS_Junio, aes(x = wd, y = ws, fill = manganese, size = manganese)) + 
    coord_polar() + 
    geom_point(shape = 21, show.legend = TRUE) + 
    scale_size(range = c(3,12), 
      labels = c("50", "150", "450", "1350", "4050"), 
      breaks = c(50, 150, 450, 1350, 4050), 
      limits = c(1,4050), 
      name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) + 
    scale_fill_gradientn(colours = c("darkblue","blue", "yellow", "orange", "red"), 
         space = "Lab", 
         guide = "legend", 
         values = rescale(c(0, 150, 450, 1350, 4401), 
             from = c(0, 4401)), 
         labels = c("50", "150", "450", "1350", "4050"), 
         breaks = c(50, 150, 450, 1350, 4050), 
         limits = c(1,4050), 
         name = expression(paste(PM[10]~bound~Mn~(ng/m^3)))) + 
    scale_x_continuous(limits= c(0,360), 
        breaks= c(0, 90, 180, 270), 
        labels = c("N","E","S","W"), 
        name = "") + 
    scale_y_continuous(name = "Distance (m)", 
        position = "left") + 
    theme_linedraw() + 
    theme(axis.text.x = element_text(size = 12), 
     axis.text.y = element_text(size = 8)) + 
    ggtitle("     NS_Enero")