{"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"4.0.5"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":274957,"sourceType":"datasetVersion","datasetId":49864}],"dockerImageVersionId":30618,"isInternetEnabled":true,"language":"r","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This R environment comes with many helpful analytics packages installed\n# It is defined by the kaggle/rstats Docker image: https://github.com/kaggle/docker-rstats\n# For example, here's a helpful package to load\n\nlibrary(tidyverse) # metapackage of all tidyverse packages\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nlist.files(path = \"../input\")\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle","execution":{"iopub.status.busy":"2024-03-23T06:25:46.005917Z","iopub.execute_input":"2024-03-23T06:25:46.008336Z","iopub.status.idle":"2024-03-23T06:25:47.307104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"library(tidyverse)\nlibrary(ggplot2)\nlibrary(lubridate)\nlibrary(modelr)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T06:28:58.913042Z","iopub.execute_input":"2024-03-23T06:28:58.962219Z","iopub.status.idle":"2024-03-23T06:28:59.080581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data <-read_csv('../input/google-play-store-apps/googleplaystore.csv')\ndata2<-read_csv('../input/google-play-store-apps/googleplaystore_user_reviews.csv')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T08:17:31.685845Z","iopub.execute_input":"2024-03-23T08:17:31.687911Z","iopub.status.idle":"2024-03-23T08:17:32.051448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#预处理\nupdate<-mdy(data[[11]])\ninstall<-(gsub(\"\\\\+\",'',data[[6]]))\ninstall<-(gsub(\",\",'',install))%>%as.numeric(install)\nsize<-(gsub(\"M\",'',data[[5]]))%>%as.numeric()\ndata<-data.frame(cbind(data,install))\ndata<-data.frame(cbind(data,size))\ndata<-data.frame(cbind(data,update))%>%select(-Installs,-Last.Updated,-Size)\ndata_mean<-data%>%group_by(Category)%>%\n  summarize(mean_Review=sum(Reviews)/n(),\n            mean_Rating=sum(Rating,na.rm = TRUE)/n(),\n            mean_install=sum(install,na.rm = TRUE)/n(),\n            mean_size=sum(size,na.rm = TRUE)/n(),\n  )%>%arrange(desc(mean_Review))\ndata_mean%>%head()","metadata":{"execution":{"iopub.status.busy":"2024-03-23T08:17:36.201139Z","iopub.execute_input":"2024-03-23T08:17:36.203008Z","iopub.status.idle":"2024-03-23T08:17:36.392449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 图1单变量 ：barplot <黑白图>\n#对比paid 的app 与 free的app数量 \na = table(data%>%filter(Type!='NaN',Type!='0')%>%pull(Type))\nbarplot(height=a,names=names(a),xlab='Type',col.lab='orange',font.lab=2,cex.lab=2)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:00:09.800711Z","iopub.execute_input":"2024-03-23T11:00:09.802636Z","iopub.status.idle":"2024-03-23T11:00:09.899852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图1：同时使用ggplot2绘制\ndata%>%filter(Type!='NaN',Type!='0')%>%ggplot(aes(Type,fill=Type))+geom_bar()","metadata":{"execution":{"iopub.status.busy":"2024-03-23T06:50:36.972668Z","iopub.execute_input":"2024-03-23T06:50:36.974712Z","iopub.status.idle":"2024-03-23T06:50:37.583225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图2：单变量 Histogram\n#内存大小的分布情况\nhist(data%>%filter(size != 'NaN')%>%pull(size),col.lab='orange',xlab='size',ylab='number',main='distribution of size')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:11:41.785746Z","iopub.execute_input":"2024-03-23T07:11:41.788046Z","iopub.status.idle":"2024-03-23T07:11:41.895796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图3： boxplot\n# Boxplot basic\n\ndata%>%filter(install!='NA')%>%ggplot()+geom_boxplot(aes(reorder(install,Reviews,median),Reviews))+labs(title='install')\nggplot(data)+geom_point(aes(Reviews,install))","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:36:32.437724Z","iopub.execute_input":"2024-03-23T07:36:32.440665Z","iopub.status.idle":"2024-03-23T07:36:34.007608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图4 violin chart\n\n#data$Category = with(data,reorder(Category,size,median))\ndata%>%\n    ggplot(aes(x=Category,y=size,fill=Category))+\n    geom_violin()+\n    xlab('category')+\n    theme(axis.text.x = element_text(angle = 90,hjust =1,vjust =0.5))+\n    theme(legend.position=\"none\")\n    xlab('')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:59:30.962175Z","iopub.execute_input":"2024-03-23T07:59:30.964489Z","iopub.status.idle":"2024-03-23T07:59:32.372508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#关系图\n#图5：Install的柱状图；排名\ndata%>%filter(install=='1e+09')%>%\n  select(Category,Reviews)%>%group_by(Category)%>%summarize(count=n())%>%\n  ggplot()+geom_bar(aes(reorder(Category,count,median),count,fill=Category),stat='identity')+coord_flip()+guides(fill='none')+labs(x='category')+labs(title='The count of the highest install at every category')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T08:01:19.068444Z","iopub.execute_input":"2024-03-23T08:01:19.070718Z","iopub.status.idle":"2024-03-23T08:01:19.483403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图6wordcloud (不同类型app的数量词云图)\n\nlibrary(wordcloud2)\n\na = table(data%>%filter(Category!='NaN')%>%pull(Category))\nwordcloud2(data=a,size=1.6)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-23T08:10:50.110586Z","iopub.execute_input":"2024-03-23T08:10:50.112668Z","iopub.status.idle":"2024-03-23T08:10:50.240448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图7 雷达图\n#选取一个GAME类型 app与同类app做评分对比\ndata_max<-data%>%filter(Category=='GAME')%>%\n  summarise(Reviews=max(Reviews,na.rm=TRUE),\n            Rating=max(Rating,na.rm = TRUE),\n            install=max(install,na.rm = TRUE),\n            size=max(size,na.rm = TRUE))\n\ndata_min<-data%>%filter(Category=='GAME')%>%\n  summarise(Reviews=min(Reviews,na.rm=TRUE),\n            Rating=min(Rating,na.rm = TRUE),\n            install=min(install,na.rm = TRUE),\n            size=min(size,na.rm = TRUE))\n\np<- data%>%filter(App=='Solitaire+')%>%select('Reviews','Rating','install','size')\np<-rbind(data_max,data_min,p)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T08:58:48.226623Z","iopub.execute_input":"2024-03-23T08:58:48.228578Z","iopub.status.idle":"2024-03-23T08:58:48.272862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"library(fmsb)\nradarchart(p,pfcol=rgb(0.2,0.5,0.5,0.5))","metadata":{"execution":{"iopub.status.busy":"2024-03-23T09:00:17.600346Z","iopub.execute_input":"2024-03-23T09:00:17.603312Z","iopub.status.idle":"2024-03-23T09:00:17.717979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图8 Lollipop chat 类似柱状图\nb<-table(data%>%filter(Category!='NaN')%>%pull(Category))\n\nggplot(as.data.frame(b),aes(x=Var1, y=Freq)) +\n  geom_segment( aes(x=Var1, xend=Var1, y=0, yend=Freq)) +\n  geom_point( size=5, color=\"red\", fill=alpha(\"orange\", 0.3), alpha=0.7, shape=21, stroke=2)+\n  theme(axis.text.x = element_text(angle = 90,hjust =1,vjust =0.5))","metadata":{"execution":{"iopub.status.busy":"2024-03-23T09:19:42.259696Z","iopub.execute_input":"2024-03-23T09:19:42.263446Z","iopub.status.idle":"2024-03-23T09:19:42.593565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图9：Treemap\n#占比\nlibrary(treemap)\n\nt<-data2%>%count(Sentiment)\ntreemap(t,index='Sentiment',vSize='n',type='index')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:45:22.334692Z","iopub.execute_input":"2024-03-23T12:45:22.336738Z","iopub.status.idle":"2024-03-23T12:45:22.531889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data2%>%count(Sentiment)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:40:45.307554Z","iopub.execute_input":"2024-03-23T12:40:45.310360Z","iopub.status.idle":"2024-03-23T12:40:45.366720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图10 散点图1\n#不同类型的均值关系\nggplot(data_mean,aes(mean_Review,mean_install))+\n  geom_point(aes(color=Category))+ggrepel::geom_label_repel(aes(label=Category))+theme(legend.position = 'none')\n","metadata":{"execution":{"iopub.status.busy":"2024-03-23T09:51:42.165826Z","iopub.execute_input":"2024-03-23T09:51:42.170503Z","iopub.status.idle":"2024-03-23T09:51:43.422604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图11：气泡图\n\nggplot(data_mean, aes(x=mean_Review, y=mean_install, size = mean_size,color=Category)) +\n    geom_point(alpha=0.5) +\n    ggrepel::geom_label_repel(aes(label=Category))+theme(legend.position = 'none')\n    ","metadata":{"execution":{"iopub.status.busy":"2024-03-23T10:00:35.154481Z","iopub.execute_input":"2024-03-23T10:00:35.157583Z","iopub.status.idle":"2024-03-23T10:00:36.539134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图12 ：升级版barplot\ncategory_type <- data %>% \n  filter(Category %in% c(\"FAMILY\", \"GAME\", \"TOOLS\", \"MEDICAL\", \"BUSINESS\", \"PRODUCTIVITY\", \"PERSONALIZATION\", \"COMMUNICATION\", \"SPORTS\", \"LIFESTYLE\"),Type %in% c(\"Free\", \"Paid\")) %>% \n  group_by(Category, Type) %>% \n  summarize(count=n()) %>% \n  arrange(desc(count))\n\nggplot(category_type, aes(Type, count, fill=Category))+geom_col(position = \"dodge\")","metadata":{"execution":{"iopub.status.busy":"2024-03-23T10:12:10.482093Z","iopub.execute_input":"2024-03-23T10:12:10.484009Z","iopub.status.idle":"2024-03-23T10:12:11.120755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图13 pie chart\npie(x= a, labels=names(a))","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:01:26.954163Z","iopub.execute_input":"2024-03-23T11:01:26.957242Z","iopub.status.idle":"2024-03-23T11:01:27.055407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图14 密度图\n#library(hrbrthemes)\ndata2%>%filter(Sentiment_Polarity!='NaN',Sentiment!='NaN')%>%\n    ggplot(aes(x=Sentiment_Polarity,group=Sentiment,fill=Sentiment))+\n    geom_density(adjust=1.5,alpha=0.4)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:22:52.499840Z","iopub.execute_input":"2024-03-23T11:22:52.501903Z","iopub.status.idle":"2024-03-23T11:22:53.074752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图15 密度图\ndata2%>%filter(Sentiment_Subjectivity!='NaN',Sentiment!='NaN')%>%\n    ggplot(aes(x=Sentiment_Subjectivity,group=Sentiment,fill=Sentiment))+\n    geom_density(adjust=1.5,alpha=0.4)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:24:09.761526Z","iopub.execute_input":"2024-03-23T11:24:09.764725Z","iopub.status.idle":"2024-03-23T11:24:10.294187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图16 ridgeline plot山脊图\nlibrary(ggridges)\n\ndata2%>%filter(Sentiment_Polarity!='NaN',Sentiment!='NaN')%>%\n    ggplot(aes(x=Sentiment_Polarity,y=Sentiment,fill=Sentiment))+\n    geom_density_ridges_gradient(alpha=0.6)+\n    theme_ridges()+\n    theme(legend.position='none')+ xlab('Sentiment_Polarity') +\n    ylab('Sentiment')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:38:39.765894Z","iopub.execute_input":"2024-03-23T11:38:39.768831Z","iopub.status.idle":"2024-03-23T11:38:40.333981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图17 heatmap with smoothing (Density2d)\n data%>% select(Rating,size) %>% ggplot(aes(x=Rating,y=size) ) +\n  stat_density_2d(aes(fill = ..density..), geom = \"raster\", contour = FALSE) +\n  scale_fill_distiller(palette=4, direction=1) +\n  scale_x_continuous(expand = c(0, 0)) +\n  scale_y_continuous(expand = c(0, 0)) + \n     labs(title=\"App Rating vs Size\",y=\"App Size\",x=\"App Rating\")\n","metadata":{"execution":{"iopub.status.busy":"2024-03-23T11:52:10.961045Z","iopub.execute_input":"2024-03-23T11:52:10.967099Z","iopub.status.idle":"2024-03-23T11:52:11.895716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图18 heatmap\ndata%>%filter(Type!=0,Type!='NaN',Content.Rating!='NaN')%>%select(Content.Rating,Rating,Type)%>%\nggplot(aes(x=Content.Rating,y=Type,fill=Rating))+\n    geom_tile()+\n    scale_fill_gradient(low=\"white\", high=\"blue\") +\n    labs(title=\"Heatmap\",y=\"Type\",x=\"Content.Rating\")+\n    theme(axis.text.x = element_text(angle = 90,hjust =1,vjust =0.5))\n        ","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:03:31.831884Z","iopub.execute_input":"2024-03-23T12:03:31.836065Z","iopub.status.idle":"2024-03-23T12:03:33.575802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图19 Type vs Rating Boxplot\ndata%>%filter(Type!=0,Type!='NaN',Rating!='NaN')%>%select(Type,Rating)%>%ggplot(aes(x=Type,y=Rating,fill=Type))+\n    geom_boxplot(alpha=0.7) +\n    stat_summary(fun.y=mean, geom=\"point\", shape=20, size=10, color=\"black\") +\n    theme(legend.position=\"none\")","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:28:59.226651Z","iopub.execute_input":"2024-03-23T12:28:59.228853Z","iopub.status.idle":"2024-03-23T12:28:59.802987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#图20 散点图 Scaterplot\npositivedata<-data2%>%filter(Sentiment=='Positive')\nnegativedata<-data2%>%filter(Sentiment=='Negative')\n\npositivedata%>%ggplot(aes(x=Sentiment_Polarity,y=Sentiment_Subjectivity))+\n    geom_point(color='#D3D3D3')+\n     geom_smooth(method=lm , color='#000000', se=FALSE)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:14:19.854299Z","iopub.execute_input":"2024-03-23T12:14:19.857191Z","iopub.status.idle":"2024-03-23T12:14:21.695483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"negativedata%>%ggplot(aes(x=Sentiment_Polarity,y=Sentiment_Subjectivity))+\n    geom_point(color='#D3D3D3')+\n     geom_smooth(method=lm , color='#000000', se=FALSE)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T12:14:52.780405Z","iopub.execute_input":"2024-03-23T12:14:52.782317Z","iopub.status.idle":"2024-03-23T12:14:53.547724Z"},"trusted":true},"execution_count":null,"outputs":[]}]}