2017-01-18 36 views
2
ggplot(mtcars) + 
    geom_point(aes(x = wt, y = mpg, size = qsec), color = 'red') + 
    geom_text(aes(wt, mpg, label=cyl)) + 
    geom_text_repel(aes(wt, mpg, label = rownames(mtcars))) + 
    theme_classic(base_size = 16) 

如果你運行這段代碼,你會得到一個情節,看起來像這樣: enter image description here 什麼我有興趣做的就是改變qseq的順序。意思是,biggest qsec將被分配smaller圓,而最小的qsec將被分配較大的一個。顯示值

我該怎麼做?

+0

可能創建一個變量'$ DF qsecInv < - 1/df $ qsec'或類似的東西並使用它。 – lmo

+0

@Imo這是一個很好的解決方法,但我將如何正確顯示圖例? – Mixalis

回答

2

加入scale_size(trans = "reverse")解決您的問題:

ggplot(mtcars) + 
    geom_point(aes(x = wt, y = mpg, size = qsec), color = 'red') + 
    geom_text(aes(wt, mpg, label=cyl)) + 
    geom_text_repel(aes(wt, mpg, label = rownames(mtcars))) + 
    theme_classic(base_size = 16)+ 
    scale_size(trans = "reverse") 

我只添加數據的圖片,以幫助別人這個問題 enter image description here

+0

哇!謝謝你,先生! – Mixalis