2016-01-21 16 views
-1

我有一個數據幀如下:如何在R中的數據表中選擇x軸的某些要求繪製圖形?

>str(df) 
'data.frame': 22673 obs. of 6 variables: 

$ V1 : Factor w/ 39 levels "2015-02-09","2015-02-09 ",..: 1 1 1 1 1 1 1 1 1 1 ... 
$ V2 : Factor w/ 10465 levels "00:48:26","01:49:26",..: 3949 3956 3964 3985 4196 4254 4262 4268 4275 4309 ... 
$ V3 : Factor w/ 3 levels "Admin","AmbassadorSchoolPlayer",..: 3 3 3 3 3 3 3 3 1 3 ... 
$ V4 : Factor w/ 104 levels "1builder1","22mAsgarfus",..: 77 77 57 77 48 48 48 48 6 77 ... 
$ V5 : Factor w/ 8580 levels ""," - -?"," - 14 1",..: 2306 874 7433 3650 2306 2306 3364 6501 3257 2306 ... 

df$V4是USER_NAME,我想要繪製這需要df$V1作爲x軸,df$V4作爲y軸的曲線圖。但是考慮到用戶數量太大,我想選擇出現在數據框中的閾值次數(比如10)的那些(用戶名)。我該怎麼做?我對R很新,我已經閱讀了幾篇介紹ggplot2的文章,但沒有找到答案。先謝謝你。

回答

0

使用表函數

count <- table(df$V4) 

子集有超過10項

使用者名稱
some_usernames <- names(count[count>10]) 

然後子集的數據幀

df_subset <- df[df$V4 %in% some_usernames, ] 

然後用GGPLOT2或基地圖形做什麼你要。希望這可以幫助。

+1

感謝您的幫助!有用!你真好! – southdoor

相關問題