第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

控制ggplot2圖例顯示順序

控制ggplot2圖例顯示順序

阿晨1998 2019-12-25 14:39:58
有誰知道如何在ggplot2中控制圖例的順序?從我可以看到的順序來看,出現(xiàn)的順序與實際的比例標簽有關(guān),而不是與比例尺聲明順序有關(guān)。更改比例尺標題會更改順序。我用菱形數(shù)據(jù)集做了一個小例子來強調(diào)這一點。我正在嘗試將ggplot2用于一系列繪圖,我想使一個變量出現(xiàn)在所有繪圖的右側(cè)。目前,雖然這種情況僅發(fā)生在其中的一些情況下,但我在如何執(zhí)行所需訂購的同時保留適當(dāng)?shù)谋壤邩撕炆弦粺o所知。library(ggplot2)diamond.data <- diamonds[sample(nrow(diamonds), 1000), ]plot <- ggplot(diamond.data, aes(carat, price, colour = clarity, shape = cut)) +  geom_point() + opts(legend.position = "top", legend.box = "horizontal")plot # the legend will appear shape then colour plot + labs(colour = "A", shape = "B") # legend will be colour then shapeplot + labs(colour = "Clarity", shape = "Cut") # legend will be shape then colour
查看完整描述

2 回答

?
萬千封印

TA貢獻1891條經(jīng)驗 獲得超3個贊

在0.9.1中,確定圖例順序的規(guī)則是秘密且不可預(yù)測的?,F(xiàn)在,在github中的dev版本0.9.2中,您可以使用參數(shù)設(shè)置圖例的順序。


這是示例:


plot <- ggplot(diamond.data, aes(carat, price, colour = clarity, shape = cut)) +

  geom_point() + opts(legend.position = "top")


plot + guides(colour = guide_legend(order = 1), 

              shape = guide_legend(order = 2))


plot + guides(colour = guide_legend(order = 2), 

              shape = guide_legend(order = 1))


查看完整回答
反對 回復(fù) 2019-12-25
  • 2 回答
  • 0 關(guān)注
  • 721 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號