使用boxplot查找并显示最佳和最差项目

问题描述 投票:3回答:1

我是来自jester_dataset_2.zip项目的笑话数据集2(Jester)的数据集,我想将笑话分成具有相似评级的笑话组,并适当地可视化结果。

数据看起来像这样

> str(tabulka)
'data.frame':   1761439 obs. of  3 variables:
 $ User  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Joke  : int  5 7 8 13 15 16 17 18 19 20 ...
 $ Rating: num  0.219 -9.281 -9.281 -6.781 0.875 ...

这是Dataset 2的一个子集。

> head(tabulka)
  User Joke Rating
1    1    5  0.219
2    1    7 -9.281
3    1    8 -9.281
4    1   13 -6.781
5    1   15  0.875
6    1   16 -9.656

我发现我不能使用ANOVA,因为均匀性不一样。因此我在R.的agricolae包中使用Kruskal-Wallis方法。

KWtest <- with ( tabulka , kruskal ( Rating , Joke ))

这是小组。

> head(KWtest$groups)
  trt   means  M
1  53 1085099  a
2 105 1083264  a
3  89 1077435 ab
4 129 1072706  b
5  35 1070016 bc
6  32 1062102  c

问题是我不知道如何恰当地将笑话组可视化。我使用boxplot来显示每个笑话的置信区间。

barvy <- c ("yellow", "grey")
boxplot (Rating ~ Joke, data = tabulka,
         col = barvy,
         xlab = "Joke",
         ylab = "Rating",
         ylim=c(-7,7))

根据KW测试给出的颜色,以适当的颜色以某种方式为每个盒子(每个笑话)着色会很好。

我怎么能这样做?或者是否有更好的方法可以在数据集中找到最好和最差的笑话?

r rating rating-system recommender-systems kruskal-wallis
1个回答
2
投票

有趣的问题本身。根据笑话所属的组,很容易为每个栏着色。但是,我认为这只是一个中间解决方案,必须有更好的可视化这些数据。所以,当然不是最好的,但有我的版本:

library(tidyverse)

# download data (jokes, part 1) to temporaty file, and unzip
tmp <- tempfile()
download.file("http://eigentaste.berkeley.edu/dataset/jester_dataset_1_1.zip", tmp)
tmp <- unzip(tmp)

# read data from temp
vtipy <- readxl::read_excel(tmp, col_names = F, na = '99')

# clean data
vtipy <- vtipy %>%
  mutate(user = 1:n()) %>%
  gather(key = 'joke', value = 'rating', -c('..1', 'user')) %>%
  rename(n = '..1', ) %>%
  filter(!is.na(rating)) %>%
  mutate(joke = as.character(as.numeric(gsub('\\.+', '', joke)) - 1)) %>%
  select(user, n, joke, rating)

# your code
KWtest <- with(vtipy, agricolae::kruskal(rating, joke))

# join groups from KWtest to original data, clean and plot
KWtest$groups %>%
  rownames_to_column('joke') %>%
  select(joke, groups) %>%
  right_join(vtipy, by = 'joke') %>% 
  mutate(joke = stringi::stri_pad_left(joke, 3, '0')) %>%
  ggplot(aes(x = joke, y = rating, fill = groups)) +
  geom_boxplot(show.legend = F) +
  scale_x_discrete(breaks = stringi::stri_pad_left(c(1, seq(5, 100, by = 5)), 3, '0')) +
  ggthemes::theme_tufte() +
  labs(x = 'Joke', y = 'Rating')

jokes

© www.soinside.com 2019 - 2024. All rights reserved.