2017-12-08 28 views
0

scatterpieを使用して6種類のパイを作りたいと思います。パイを構成する101のカテゴリーがあります(すべてのパイに101があるわけではありません)ので、色を区別することができます。scatterpieでの色の正しい使用

私は空白の画面を取得し、次のように手動で色を設定しようとする場合、これはその後、私には十分な色(私はパイを見て、伝えることができます)

ggplot(wholebody_cutLH_wide_t) + 
# annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + 
geom_scatterpie(aes(x=imX, y=imY,r=radius), 
      data=wholebody_cutLH_wide_t,  cols=colnames(wholebody_cutLH_wide_t[1:101]),color=NA) + 
#scale_color_manual(values=sample(allcolors,101)) + 
scale_x_continuous(expand=c(0,0), lim=c(0,3)) + 
scale_y_continuous(expand=c(0,0), lim=c(0,6)) + 
theme(legend.position="none", 
    panel.background = element_rect(fill = "transparent") # bg of the panel 
    , plot.background = element_rect(fill = "transparent") # bg of the plot 
    , panel.grid.major = element_blank() # get rid of major grid 
    , panel.grid.minor = element_blank(), # get rid of minor grid 
    line = element_blank(), 
    text = element_blank(), 
    title = element_blank() 
) 

enter image description here

を与えるものではありません。 スキャッタピー(color = sample(allcolors、101))で色を設定しようとすると、エラーが発生する

エラー:美学の長さはデータ1(2864)と同じでなければなりません:color

allcolors = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)] 
ggplot(wholebody_cutLH_wide_t) + 
# annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + 
geom_scatterpie(aes(x=imX, y=imY,r=radius), 
      data=wholebody_cutLH_wide_t, cols=colnames(wholebody_cutLH_wide_t[1:101]),color=NA) + 
scale_color_manual(values=sample(allcolors,101)) + 
scale_x_continuous(expand=c(0,0), lim=c(0,3)) + 
scale_y_continuous(expand=c(0,0), lim=c(0,6)) + 
theme(legend.position="none", 
    panel.background = element_rect(fill = "transparent") # bg of the panel 
    , plot.background = element_rect(fill = "transparent") # bg of the plot 
    , panel.grid.major = element_blank() # get rid of major grid 
    , panel.grid.minor = element_blank(), # get rid of minor grid 
    line = element_blank(), 
    text = element_blank(), 
    title = element_blank() 
) 
+0

は 'COLNAMES(wholebody_cutLH_wide_t [1:101])というよろしいですプロットである'正しいですか?または、それは 'colnames(wholebody_cutLH_wide_t)[1:101]'であるべきですか? –

+0

奇妙な、はいブラケットが間違った場所にあったが、それを修正してプロットを変更しない – user2814482

+0

あなたは正しいです、私はブラケットを間違って配置しましたが、私はそれを修正するときにまだ色の欠如 – user2814482

答えて

1

ここに最終的な作業コードがあります。 scale_color_manualをscale_fill_manualに切り替える必要がありました。

ggplot(wholebody_cutLH_wide_t) + 
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + 
geom_scatterpie(aes(x=imX, y=imY,r=radius), 
      data=wholebody_cutLH_wide_t, cols=colnames(wholebody_cutLH_wide_t)[1:101],color=NA) + 
scale_fill_manual(values=sample(allcolors,101)) + 
scale_x_continuous(expand=c(0,0), lim=c(0,3)) + 
scale_y_continuous(expand=c(0,0), lim=c(0,6)) + 
theme(legend.position="none", 
    panel.background = element_rect(fill = "transparent") # bg of the panel 
    , plot.background = element_rect(fill = "transparent") # bg of the plot 
    , panel.grid.major = element_blank() # get rid of major grid 
    , panel.grid.minor = element_blank(), # get rid of minor grid 
    line = element_blank(), 
    text = element_blank(), 
    title = element_blank() 
) 

そしてここ

enter image description here

関連する問題