本篇內容介紹了“怎么用ggplot2的geom_point繪制散點圖”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
ggplot2可以利用geom_point繪制散點圖,而點的形狀控制參數shape會顯示多少效果呢?(注意此處只介紹shape的設定,不是aes(shape)映射)
可以通過查詢?shape
獲得以下內容:
# Shape examples # Shape takes four types of values: an integer in [0, 25], # a single character-- which uses that character as the plotting symbol, # a . to draw the smallest rectangle that is visible (i.e., about one pixel) # an NA to draw nothing p + geom_point() p + geom_point(shape = 5) p + geom_point(shape = "k", size = 3) p + geom_point(shape = ".") p + geom_point(shape = NA)
1、[0,25]之間的數值表示不同的形狀
利用下數據固定X,Y,shape
dat X Y shape 1 1 6 0 2 2 6 1 3 3 6 2 4 4 6 3 5 5 6 4 6 1 5 5 7 2 5 6 8 3 5 7 9 4 5 8 10 5 5 9 11 1 4 10 12 2 4 11 13 3 4 12 14 4 4 13 15 5 4 14 16 1 3 15 17 2 3 16 18 3 3 17 19 4 3 18 20 5 3 19 21 1 2 20 22 2 2 21 23 3 2 22 24 4 2 23 25 5 2 24 26 1 1 25
代碼中確定X ,Y,在shape中設定下形狀。
library(ggplot2) p=ggplot(dat,aes(x=X,y=Y))+ geom_point(shape=dat$shape,size=10) print(p)
每個位置對應的形狀的數字(結合數據和圖片)
如果統一一個形狀呢?
p=ggplot(dat,aes(x=X,y=Y))+ geom_point(shape=5,size=10) print(p)
2、如果等于“k"呢?將顯示"k"
p=ggplot(dat,aes(x=X,y=Y))+ geom_point(shape="k",size=10) print(p)
3、如果shape是"." 將繪出有一個非常小的點(此時的size并沒能調整到大?。?/p>
p=ggplot(dat,aes(x=X,y=Y))+ geom_point(shape=".",size=20) print(p)
4如果shape是NA 則隱藏點
p=ggplot(dat,aes(x=X,y=Y))+ geom_point(shape=NA,size=10) print(p)
“怎么用ggplot2的geom_point繪制散點圖”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。