I have the dataframe below and I create a box plot but I cannot see the boxes for some reason.Is it because of my values? How can I display them?
df<-structure(list(Comedy = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 192993657, 2027127534, 1826083072, 1128287155,
1757374990, 2694138537, 3190204219, 2038778526), Education = c(943330388,
1155823837, 1360355713, 1826278073, 2188996970, 2021212414, 2289941566,
2127165749, 1783936602, 2872498991, 2853872150, 3064968119, 3215161644,
3049311469, 2820083900, 2044822024, 3779135880, 2844133676, 3376034265,
3041618231, 3105665413, 3550804553, 3539721850, 4456458622, 4991538788,
5828853483, 4966268171, 4512424020, 4502737563, 4375577460, 4552548135,
3738145324, 3995222561, 3953186608, 3594443364, 3585009005, 2700428379,
2902711237, 2359179701, 2740895126, 1867652957, 2048359210, 2314370309,
2998250015, 3491065357, 3903773976, 2935444472), Entertainment = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7788928842, 7204965173,
6992191235, 5457111773, 6860197195, 8855099815, 10013159307,
10474839762, 9524669175), `Film & Animation` = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 759717307,
615753280, 318711634, 333904916, -693533921, 2091024234, 950022270,
1001308730, 1026354524, 1081811412, 1199434291, 1433216491, 1442529761,
1532974436, 1395606514, 1363861251, 1389014794, 1593050956, 1685049970,
1547131073, 1518807877, 1233700577, 1218615927, 1454858377, 1352274781
), Gaming = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2510727459, 2443299082, 3488510114, 5039516826, 3532430927, 3672818367, 3326539144,
3130946776, 3280046870, 3691388930, 2605046632), `Howto & Style` = c(543234645,
637460061, 715598918, 853921148, 863342506, 795767480, 746997762,
653842221, 788862290, 591282170, 568671091, 548087579, 485300284,
436535293, 568286241, 478040015, 521541708, 405161168, 319837479,
280725401, 360157763, 165904320, 212343880, 327743010, 395400144,
426654776, 366884505, 357665076, 364828829, 345995485, 297049174,
240780776, 274207911, 273912428, 319470376, 392600212, 360147433,
264181288, 251605545, 236415550, 204441940, 421922863, 256820429,
424107264, 431256372, 390931344, 274420963), Music = c(45831420,
38904148, 73012836, 84645886, 111060240, 57262179, 26950500,
39134840, 60187872, 47610185, 23140910, 25985719, 28712442, 25722654,
47876708, 25865517, 32238860, 40636947, 44902937, 55838200, 36025492,
28671767, 82421655, 31274307, 42413334, 7507664, 35619244, -11045119,
37486877, 20923182, 27529830, 30924536, 28565411, 39739293, 23233821,
115184742, 25449369, 23944670, 41185546, -16964201, 47813282,
21983523, 17880023, 13962494, 12342364, 13356074, 13021208),
`People & Blogs` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 398375824, 454784769, 370688348, 369779164, 500101683,833749803, 1063138342, 1479795070, 1619160390, 1834784208,
2111705491, 1350498139), `Science & Technology` = c(27301292,
39573248, 48043856, 39855934, 52061005, 49053872, 49842103,
44976795, 124632168, 50023068, 62941217, 47587876, 77099065,
84765100, 58321781, 91284611, 96894838, 94260454, 72295712,
102476421, 127194669, 67833402, 83318605, 114770114, 65328120,
142092816, 123237585, 88539117, 176004414, 125341790, 142739116,
86111812, 160017617, 131590671, 112033237, 129916112, 122655167,
135571501, 63475989, 116497124, 94155011, 100342778, 90332692,
88069070, 138735396, 76689085, 48123575), Sports = c(160818771,
208830991, 189706047, 254772059, 310324223, 175281803, 245742536,
213430460, 221505212, 231476966, 175724338, 258531007, 190968565,
223061017, 210376637, 260369412, 289167706, 200040944, 260041965,
200611576, 169604151, 276707678, 215539732, 214705917, 175674357,
278796775, 285834056, 181252193, 270411741, 188726163, 189031053,
155748840, 195702049, 160777215, 163685423, 191998118, 150304968,
133674014, 162583897, 142010262, 123440234, 99242284, 100782041,
81297079, 94100459, 123463360, 104218370)), class = "data.frame", row.names = c("2018-03",
"2018-04", "2018-05", "2018-06", "2018-07", "2018-08", "2018-09",
"2018-10", "2018-11", "2018-12", "2019-01", "2019-02", "2019-03","2019-04", "2019-05", "2019-06", "2019-07", "2019-08", "2019-09",
"2019-10", "2019-11", "2019-12", "2020-01", "2020-02", "2020-03",
"2020-04", "2020-05", "2020-06", "2020-07", "2020-08", "2020-09",
"2020-10", "2020-12", "2021-01", "2021-02", "2021-03", "2021-04",
"2021-05", "2021-06", "2021-07", "2021-08", "2021-09", "2021-10",
"2021-11", "2021-12", "2022-01", "2022-02"))
p<-ggplot(df, aes(x=WORDS, y=TOTALS, fill=WORDS))
geom_boxplot()
p theme_minimal() theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
xlab("Industries") ylab("Value")
CodePudding user response:
With the new data, it is in 'wide' format. We can reshape to 'long' with pivot_longer
and it should work
library(dplyr)
library(tidyr)
library(ggplot2)
df_long <- pivot_longer(df, cols = everything(), names_to = 'WORDS',
values_to = 'TOTALS')
p <- ggplot(df_long, aes(x = WORDS, y = TOTALS, fill = WORDS))
geom_boxplot()
p
theme_minimal()
theme(axis.text.x = element_text(angle = 90, vjust = 0.5,
hjust=1))
xlab("Industries")
ylab("Value")
-output