Data not appearing on my histogram

Hey guys I'm new to here and RStudio. I've no idea why my histogram is not inputting data from my Returns.

Below is my current code:

bins<-stocks%>%
select(Returns)%>%
group_by(symbol)%>%
summarise("n" = n(),
"Rice Rule" = 2*n^1/3)

bins


BINS<- bins[1,3]

stocks%>%
  group_by(symbol)%>%
  select(symbol, Returns)

ggplot(stocks, aes(Returns))+
  geom_histogram(bins= BINS)+
  facet_wrap(~symbol)

The histogram is blank:

Any ideas? Thanks

There are various problems with your code, but let's start with the heart of the matter. In

ggplot(stocks, aes(Returns))+
  geom_histogram(bins= BINS)+
  facet_wrap(~symbol)

what is the value of BINS?

Problems in the code:

  1. In
select(Returns)%>%
group_by(symbol)%>%
summarise("n" = n(),
"Rice Rule" = 2*n^1/3)

the select() function keeps only the Returns column of stocks. The group_by(symbol) should throw an error unless select() is adding columns back in due to previous grouping. I would drop the select() line of code; it is unnecessary.
"Rice Rule" = 2*n^1/3) is calculating 2*(n^1)/3. I think you want 2*n^(1/3).
I would avoid column names with spaces.

  1. BINS<- bins[1,3]
    It is not clear why you are only using the Rice Rule value in the first row.

stocks%>%
  group_by(symbol)%>%
  select(symbol, Returns)

The above code's output is not stored, so the stocks data frame is unchanged.

Thanks so much for pointing out my error in formula! My BINS value is now 36.10668 instead of the 3k+ I had...

However the bins value is still not included in the formula for some reason so the histogram is still not showing up. I'm also super confused on what you meant by points 2 and 3, could you elaborate for me? Thanks...

  1. The bins data frame should be calculated with
bins<-stocks%>%
group_by(symbol)%>%
summarise(n = n(),
Rice_Rule = 2*n^(1/3))

It will have three column: symbol, n, and Rice_Rule, with one row for each symbol. You then set
BINS< - bins[1,3]
That sets BINS to the value of the Rice_Rule column in the first row. That is not necessarily wrong but it's strange to calculate a Rice_Rule value for each symbol and then use only one of them.

  1. When you run
stocks%>%
  group_by(symbol)%>%
  select(symbol, Returns)

the output goes to the console but is not stored in a variable. You could make a new version of the stocks data frame with

stocks <- stocks%>%
  group_by(symbol)%>%
  select(symbol, Returns)

However, I don't see the point of grouping and selecting columns from stocks at that point. It will not change the plot in any way.

What do you get if you run

ggplot(stocks, aes(Returns))+
  geom_histogram()+
  facet_wrap(~symbol)

Please post the output of
str(stocks)

Well I get 3 blank histograms...
This is for str(stocks)

I can't account for what your are seeing. Please post the output of

dput(head(stocks, 100))

dput(head(stocks, 100))
structure(list(symbol = c("RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
"RCL", "RCL", "RCL", "RCL", "RCL"), date = structure(c(10959,
10960, 10961, 10962, 10963, 10966, 10967, 10968, 10969, 10970,
10974, 10975, 10976, 10977, 10980, 10981, 10982, 10983, 10984,
10987, 10988, 10989, 10990, 10991, 10994, 10995, 10996, 10997,
10998, 11001, 11002, 11003, 11004, 11005, 11009, 11010, 11011,
11012, 11015, 11016, 11017, 11018, 11019, 11022, 11023, 11024,
11025, 11026, 11029, 11030, 11031, 11032, 11033, 11036, 11037,
11038, 11039, 11040, 11043, 11044, 11045, 11046, 11047, 11050,
11051, 11052, 11053, 11054, 11057, 11058, 11059, 11060, 11061,
11064, 11065, 11066, 11067, 11071, 11072, 11073, 11074, 11075,
11078, 11079, 11080, 11081, 11082, 11085, 11086, 11087, 11088,
11089, 11092, 11093, 11094, 11095, 11096, 11099, 11100, 11101
), class = "Date"), open = c(49.0625, 46.375, 45.0625, 47.3125,
48.25, 49.5, 54.5, 52.25, 52.5625, 53.875, 55, 54.5, 55.375,
55, 54.125, 51.5, 52.6875, 55, 54, 50.9375, 49.5, 47.5, 47.1875,
48.25, 47.6875, 45.1875, 45.125, 45.125, 45.125, 41.875, 37,
37.75, 37.625, 37.9375, 37, 37.125, 36.25, 34.9375, 34, 35.375,
34.75, 28.75, 28.875, 29.25, 28.75, 27.5, 27.5, 27.75, 26.625,
26.75, 26, 28, 31.5, 28.75, 28.6875, 29.1875, 30, 30.75, 31.1875,
30.125, 30.625, 30, 29.75, 28.1875, 27.125, 26.4375, 26.5, 26.3125,
26.0625, 26, 25.125, 25, 23.625, 23.4375, 23.5, 24.5, 24.25,
24.625, 22.625, 21.9375, 21.375, 21.125, 21.5, 20.875, 22, 23.375,
23.125, 23.0625, 23.25, 22.75, 22.6875, 22.25, 23.25, 24.25,
24.3125, 23.25, 24.25, 24.125, 23.375, 22.875), high = c(49.1875,
46.375, 47.625, 49.125, 49.5, 52.4375, 54.5, 52.875, 53.6875,
56.375, 55.4375, 55.75, 55.875, 55.125, 54.125, 53.3125, 55.1875,
55, 54, 50.9375, 49.5, 48.4375, 48.5, 48.625, 47.6875, 45.625,
45.9375, 45.5625, 45.125, 41.875, 37.75, 39, 39.125, 37.9375,
37.625, 37.375, 36.25, 35.3125, 34.375, 36.625, 34.75, 28.9375,
29.875, 29.875, 28.875, 27.5, 27.9375, 27.75, 26.75, 26.875,
27, 33, 31.5, 30.1875, 30, 30.1875, 30.9375, 31.1875, 31.1875,
31.125, 30.625, 30.1875, 29.75, 28.3125, 27.375, 26.5625, 26.625,
26.5625, 26.375, 26, 25.3125, 25.5, 24.3125, 24, 23.75, 24.6875,
25.1875, 24.625, 22.75, 22.0625, 21.4375, 21.5625, 21.625, 21.75,
24, 24.4375, 23.5625, 23.1875, 23.6875, 22.875, 22.75, 23.1875,
23.75, 24.9375, 24.3125, 25.1875, 24.6875, 24.125, 23.5, 23.0625
), low = c(45.375, 44.8125, 44.5, 46.9375, 48, 49.25, 51.3125,
51.875, 51.75, 53.25, 54.75, 54.5, 54.5625, 53.125, 51.375, 50.75,
52.25, 53.6875, 50.75, 46, 47, 46.75, 47.1875, 47.375, 44.375,
43.75, 44.875, 44.5, 41.5, 35.5625, 35.625, 36.875, 37.5, 36.3125,
36.5625, 36.5625, 34.0625, 33.1875, 33.125, 34.6875, 28.625,
26.125, 27.6875, 28.625, 27.5, 26.5, 27, 26.6875, 26.0625, 25.75,
25.3125, 27.9375, 26, 27.875, 28.375, 29.1875, 30, 30.75, 30.0625,
30.125, 29.75, 29.0625, 28, 26.375, 25.5625, 25.5625, 25.875,
25.875, 25.375, 24.875, 24.5625, 24.75, 22.9375, 23, 22.5, 23.875,
24.25, 22.5, 21.3125, 21.125, 19.8125, 20.75, 20.5, 20.8125,
22, 23.375, 22.4375, 22.6875, 22.0625, 22.1875, 22.375, 22.25,
23, 23.875, 23.4375, 23.25, 23.9375, 23.125, 22.8125, 22.125),
close = c(46.375, 44.8125, 47.5625, 48.5, 49.25, 51.9375,
52.125, 52.3125, 53.625, 55.6875, 55.1875, 55.4375, 54.75,
53.75, 52.25, 52.4375, 55, 53.75, 51.375, 49.4375, 47.375,
46.9375, 48.1875, 47.6875, 44.6875, 45, 45, 45, 41.75, 36.5,
37.4375, 37.25, 37.6875, 36.5, 37.0625, 36.6875, 34.5, 33.9375,
33.9375, 35.375, 29.375, 28.375, 29, 29, 27.75, 26.796875,
27.5, 26.875, 26.125, 26, 27, 31.5, 28.6875, 28.375, 30,
29.875, 30.5625, 30.75, 30.9375, 30.75, 30, 29.5, 28, 26.5,
26.4375, 26, 26.0625, 26.0625, 25.875, 25, 24.75, 25.0625,
23, 23.75, 23.75, 24.5, 24.5, 22.5625, 21.9375, 21.4375,
21, 20.8125, 21, 21.4375, 22.9375, 23.9375, 23.0625, 23,
22.6875, 22.4375, 22.5, 23, 23.5, 24.375, 23.75, 24.375,
24, 23.25, 22.875, 22.875), volume = c(592200, 330200, 525300,
511100, 421900, 528500, 516000, 265900, 208400, 876500, 579200,
281100, 268300, 528300, 571900, 1942200, 1744500, 772500,
930400, 1349300, 829200, 656100, 379200, 167900, 553200,
949300, 479800, 262000, 680500, 2773600, 3512600, 1290000,
808600, 407000, 350600, 267000, 303400, 683200, 1376400,
2141500, 4187500, 3086100, 3509500, 1504300, 690200, 812500,
686500, 251700, 398300, 742800, 2120300, 2289300, 1509700,
764600, 555900, 496500, 907700, 754400, 557000, 465200, 322200,
325200, 599800, 691200, 657800, 836800, 801600, 1130600,
1019200, 477000, 346000, 495200, 466700, 335900, 1006100,
302700, 647900, 1161800, 1724600, 1044300, 1473100, 901700,
1033400, 999400, 1667200, 840500, 328200, 275100, 599800,
211700, 271700, 596600, 362800, 457000, 227700, 885100, 597100,
207000, 168100, 679800), adjusted = c(33.0566787719727, 31.942892074585,
33.903133392334, 34.5713806152344, 35.1060066223145, 37.021671295166,
37.1553192138672, 37.2889862060547, 38.2245674133301, 39.6947250366211,
39.3383140563965, 39.5165138244629, 39.0264587402344, 38.3136596679688,
37.2444381713867, 37.3780975341797, 39.2046699523926, 38.3136596679688,
36.620719909668, 35.2396430969238, 33.769474029541, 33.4576225280762,
34.3486480712891, 33.9922180175781, 31.8537845611572, 32.0765419006348,
32.0765419006348, 32.0765419006348, 29.7599048614502, 26.0176486968994,
26.6859016418457, 26.5522499084473, 26.8640995025635, 26.0176486968994,
26.4185962677002, 26.1513004302979, 24.5920219421387, 24.1910648345947,
24.2697372436523, 25.2977313995361, 21.0069484710693, 20.291820526123,
20.7387714385986, 20.7387714385986, 19.8448524475098, 19.1632461547852,
19.6660785675049, 19.219123840332, 18.6827754974365, 18.5933742523193,
19.3085117340088, 22.5265941619873, 20.5152969360352, 20.291820526123,
21.4539051055908, 21.3645114898682, 21.8561668395996, 21.9902515411377,
22.1243381500244, 21.9902515411377, 21.4539051055908, 21.0963401794434,
20.0236434936523, 18.95094871521, 18.9062538146973, 18.5933742523193,
18.6380729675293, 18.6380729675293, 18.5039844512939, 17.8782558441162,
17.6994667053223, 17.922945022583, 16.4479885101318, 16.984338760376,
16.984338760376, 17.5206851959229, 17.5206851959229, 16.1351203918457,
15.6881675720215, 15.3306007385254, 15.017725944519, 14.8836460113525,
15.017725944519, 15.3306007385254, 16.4032955169678, 17.1184310913086,
16.4926834106445, 16.4479885101318, 16.224515914917, 16.0457286834717,
16.0904216766357, 16.4479885101318, 16.8055591583252, 17.4312953948975,
16.984338760376, 17.4312953948975, 17.163122177124, 16.6267700195312,
16.3586025238037, 16.3586025238037), Returns = c(NA, -3.42739409341558,
5.95577547729739, 1.95187493704656, 1.53460547340489, 5.31312071910167,
0.360349112046273, 0.359106408685155, 2.47804278288829, 3.77398733519527,
-0.901935191769481, 0.451969971163404, -1.247881070758, -1.84333634407619,
-2.83038590542415, 0.358228260307488, 4.77109656940017, -2.2989389242835,
-4.51922839229714, -3.84425247400102, -4.26144140376353,
-0.927762031369026, 2.62830215527249, -1.04310438522205,
-6.49754170975519, 0.696878158779156, 0, 0, -7.49629679731099,
-13.438690932166, 2.53602937765768, -0.502091114290665, 1.16763178534034,
-3.20157004870736, 1.52930624774647, -1.01692473331578, -6.14768398796952,
-1.64387357702998, 0.32468500230152, 4.14845304149587, -18.5861461140956,
-3.46353874674732, 2.1787089618729, 0, -4.40603137611288,
-3.49504692401273, 2.5901069723708, -2.29894347710051, -2.83038136754643,
-0.479670873372777, 3.7740726913419, 15.4150552820808, -9.35257741140739,
-1.09529247811365, 5.56888099064008, -0.417548114616236,
2.27519130803371, 0.611612644613617, 0.607903293454882, -0.607903293454895,
-2.46925583803112, -1.68071107821019, -5.21858242080634,
-5.50597556158977, -0.236123740223734, -1.66874627371168,
0.240112807979635, 0, -0.722033770301404, -3.44008675208271,
-1.00507076359777, 1.25472273389923, -8.58785461067082, 3.20884793401961,
0, 3.10905240442747, 0, -8.23839070900674, -2.80915166313562,
-2.30558911440495, -2.0619646190398, -0.896820600871524,
0.896820600871529, 2.06196461903981, 6.76313815654013, 4.26734638516585,
-3.72388717467848, -0.27136621892726, -1.36797643227116,
-1.10807378747202, 0.278147951622491, 2.19790226812068, 2.15065432390387,
3.65574426609062, -2.59755065597488, 2.59755065597488, -1.55041540516258,
-3.17489743487715, -1.62601409942161, 0)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -100L), groups = structure(list(
symbol = "RCL", .rows = structure(list(1:100), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L), .drop = TRUE))

With the data provided, ggplot() works fine. I see that version of the data does not match the str() output you posted earlier. Can you post a similarly sized data set that does fail to plot?

stocks <- structure(list(symbol = c("RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL", "RCL",
                          "RCL", "RCL", "RCL", "RCL", "RCL"), date = structure(c(10959,
                                                                                 10960, 10961, 10962, 10963, 10966, 10967, 10968, 10969, 10970,
                                                                                 10974, 10975, 10976, 10977, 10980, 10981, 10982, 10983, 10984,
                                                                                 10987, 10988, 10989, 10990, 10991, 10994, 10995, 10996, 10997,
                                                                                 10998, 11001, 11002, 11003, 11004, 11005, 11009, 11010, 11011,
                                                                                 11012, 11015, 11016, 11017, 11018, 11019, 11022, 11023, 11024,
                                                                                 11025, 11026, 11029, 11030, 11031, 11032, 11033, 11036, 11037,
                                                                                 11038, 11039, 11040, 11043, 11044, 11045, 11046, 11047, 11050,
                                                                                 11051, 11052, 11053, 11054, 11057, 11058, 11059, 11060, 11061,
                                                                                 11064, 11065, 11066, 11067, 11071, 11072, 11073, 11074, 11075,
                                                                                 11078, 11079, 11080, 11081, 11082, 11085, 11086, 11087, 11088,
                                                                                 11089, 11092, 11093, 11094, 11095, 11096, 11099, 11100, 11101
                          ), class = "Date"), open = c(49.0625, 46.375, 45.0625, 47.3125,
                                                       48.25, 49.5, 54.5, 52.25, 52.5625, 53.875, 55, 54.5, 55.375,
                                                       55, 54.125, 51.5, 52.6875, 55, 54, 50.9375, 49.5, 47.5, 47.1875,
                                                       48.25, 47.6875, 45.1875, 45.125, 45.125, 45.125, 41.875, 37,
                                                       37.75, 37.625, 37.9375, 37, 37.125, 36.25, 34.9375, 34, 35.375,
                                                       34.75, 28.75, 28.875, 29.25, 28.75, 27.5, 27.5, 27.75, 26.625,
                                                       26.75, 26, 28, 31.5, 28.75, 28.6875, 29.1875, 30, 30.75, 31.1875,
                                                       30.125, 30.625, 30, 29.75, 28.1875, 27.125, 26.4375, 26.5, 26.3125,
                                                       26.0625, 26, 25.125, 25, 23.625, 23.4375, 23.5, 24.5, 24.25,
                                                       24.625, 22.625, 21.9375, 21.375, 21.125, 21.5, 20.875, 22, 23.375,
                                                       23.125, 23.0625, 23.25, 22.75, 22.6875, 22.25, 23.25, 24.25,
                                                       24.3125, 23.25, 24.25, 24.125, 23.375, 22.875), high = c(49.1875,
                                                                                                                46.375, 47.625, 49.125, 49.5, 52.4375, 54.5, 52.875, 53.6875,
                                                                                                                56.375, 55.4375, 55.75, 55.875, 55.125, 54.125, 53.3125, 55.1875,
                                                                                                                55, 54, 50.9375, 49.5, 48.4375, 48.5, 48.625, 47.6875, 45.625,
                                                                                                                45.9375, 45.5625, 45.125, 41.875, 37.75, 39, 39.125, 37.9375,
                                                                                                                37.625, 37.375, 36.25, 35.3125, 34.375, 36.625, 34.75, 28.9375,
                                                                                                                29.875, 29.875, 28.875, 27.5, 27.9375, 27.75, 26.75, 26.875,
                                                                                                                27, 33, 31.5, 30.1875, 30, 30.1875, 30.9375, 31.1875, 31.1875,
                                                                                                                31.125, 30.625, 30.1875, 29.75, 28.3125, 27.375, 26.5625, 26.625,
                                                                                                                26.5625, 26.375, 26, 25.3125, 25.5, 24.3125, 24, 23.75, 24.6875,
                                                                                                                25.1875, 24.625, 22.75, 22.0625, 21.4375, 21.5625, 21.625, 21.75,
                                                                                                                24, 24.4375, 23.5625, 23.1875, 23.6875, 22.875, 22.75, 23.1875,
                                                                                                                23.75, 24.9375, 24.3125, 25.1875, 24.6875, 24.125, 23.5, 23.0625
                                                       ), low = c(45.375, 44.8125, 44.5, 46.9375, 48, 49.25, 51.3125,
                                                                  51.875, 51.75, 53.25, 54.75, 54.5, 54.5625, 53.125, 51.375, 50.75,
                                                                  52.25, 53.6875, 50.75, 46, 47, 46.75, 47.1875, 47.375, 44.375,
                                                                  43.75, 44.875, 44.5, 41.5, 35.5625, 35.625, 36.875, 37.5, 36.3125,
                                                                  36.5625, 36.5625, 34.0625, 33.1875, 33.125, 34.6875, 28.625,
                                                                  26.125, 27.6875, 28.625, 27.5, 26.5, 27, 26.6875, 26.0625, 25.75,
                                                                  25.3125, 27.9375, 26, 27.875, 28.375, 29.1875, 30, 30.75, 30.0625,
                                                                  30.125, 29.75, 29.0625, 28, 26.375, 25.5625, 25.5625, 25.875,
                                                                  25.875, 25.375, 24.875, 24.5625, 24.75, 22.9375, 23, 22.5, 23.875,
                                                                  24.25, 22.5, 21.3125, 21.125, 19.8125, 20.75, 20.5, 20.8125,
                                                                  22, 23.375, 22.4375, 22.6875, 22.0625, 22.1875, 22.375, 22.25,
                                                                  23, 23.875, 23.4375, 23.25, 23.9375, 23.125, 22.8125, 22.125),
               close = c(46.375, 44.8125, 47.5625, 48.5, 49.25, 51.9375,
                         52.125, 52.3125, 53.625, 55.6875, 55.1875, 55.4375, 54.75,
                         53.75, 52.25, 52.4375, 55, 53.75, 51.375, 49.4375, 47.375,
                         46.9375, 48.1875, 47.6875, 44.6875, 45, 45, 45, 41.75, 36.5,
                         37.4375, 37.25, 37.6875, 36.5, 37.0625, 36.6875, 34.5, 33.9375,
                         33.9375, 35.375, 29.375, 28.375, 29, 29, 27.75, 26.796875,
                         27.5, 26.875, 26.125, 26, 27, 31.5, 28.6875, 28.375, 30,
                         29.875, 30.5625, 30.75, 30.9375, 30.75, 30, 29.5, 28, 26.5,
                         26.4375, 26, 26.0625, 26.0625, 25.875, 25, 24.75, 25.0625,
                         23, 23.75, 23.75, 24.5, 24.5, 22.5625, 21.9375, 21.4375,
                         21, 20.8125, 21, 21.4375, 22.9375, 23.9375, 23.0625, 23,
                         22.6875, 22.4375, 22.5, 23, 23.5, 24.375, 23.75, 24.375,
                         24, 23.25, 22.875, 22.875), volume = c(592200, 330200, 525300,
                                                                511100, 421900, 528500, 516000, 265900, 208400, 876500, 579200,
                                                                281100, 268300, 528300, 571900, 1942200, 1744500, 772500,
                                                                930400, 1349300, 829200, 656100, 379200, 167900, 553200,
                                                                949300, 479800, 262000, 680500, 2773600, 3512600, 1290000,
                                                                808600, 407000, 350600, 267000, 303400, 683200, 1376400,
                                                                2141500, 4187500, 3086100, 3509500, 1504300, 690200, 812500,
                                                                686500, 251700, 398300, 742800, 2120300, 2289300, 1509700,
                                                                764600, 555900, 496500, 907700, 754400, 557000, 465200, 322200,
                                                                325200, 599800, 691200, 657800, 836800, 801600, 1130600,
                                                                1019200, 477000, 346000, 495200, 466700, 335900, 1006100,
                                                                302700, 647900, 1161800, 1724600, 1044300, 1473100, 901700,
                                                                1033400, 999400, 1667200, 840500, 328200, 275100, 599800,
                                                                211700, 271700, 596600, 362800, 457000, 227700, 885100, 597100,
                                                                207000, 168100, 679800), adjusted = c(33.0566787719727, 31.942892074585,
                                                                                                      33.903133392334, 34.5713806152344, 35.1060066223145, 37.021671295166,
                                                                                                      37.1553192138672, 37.2889862060547, 38.2245674133301, 39.6947250366211,
                                                                                                      39.3383140563965, 39.5165138244629, 39.0264587402344, 38.3136596679688,
                                                                                                      37.2444381713867, 37.3780975341797, 39.2046699523926, 38.3136596679688,
                                                                                                      36.620719909668, 35.2396430969238, 33.769474029541, 33.4576225280762,
                                                                                                      34.3486480712891, 33.9922180175781, 31.8537845611572, 32.0765419006348,
                                                                                                      32.0765419006348, 32.0765419006348, 29.7599048614502, 26.0176486968994,
                                                                                                      26.6859016418457, 26.5522499084473, 26.8640995025635, 26.0176486968994,
                                                                                                      26.4185962677002, 26.1513004302979, 24.5920219421387, 24.1910648345947,
                                                                                                      24.2697372436523, 25.2977313995361, 21.0069484710693, 20.291820526123,
                                                                                                      20.7387714385986, 20.7387714385986, 19.8448524475098, 19.1632461547852,
                                                                                                      19.6660785675049, 19.219123840332, 18.6827754974365, 18.5933742523193,
                                                                                                      19.3085117340088, 22.5265941619873, 20.5152969360352, 20.291820526123,
                                                                                                      21.4539051055908, 21.3645114898682, 21.8561668395996, 21.9902515411377,
                                                                                                      22.1243381500244, 21.9902515411377, 21.4539051055908, 21.0963401794434,
                                                                                                      20.0236434936523, 18.95094871521, 18.9062538146973, 18.5933742523193,
                                                                                                      18.6380729675293, 18.6380729675293, 18.5039844512939, 17.8782558441162,
                                                                                                      17.6994667053223, 17.922945022583, 16.4479885101318, 16.984338760376,
                                                                                                      16.984338760376, 17.5206851959229, 17.5206851959229, 16.1351203918457,
                                                                                                      15.6881675720215, 15.3306007385254, 15.017725944519, 14.8836460113525,
                                                                                                      15.017725944519, 15.3306007385254, 16.4032955169678, 17.1184310913086,
                                                                                                      16.4926834106445, 16.4479885101318, 16.224515914917, 16.0457286834717,
                                                                                                      16.0904216766357, 16.4479885101318, 16.8055591583252, 17.4312953948975,
                                                                                                      16.984338760376, 17.4312953948975, 17.163122177124, 16.6267700195312,
                                                                                                      16.3586025238037, 16.3586025238037), Returns = c(NA, -3.42739409341558,
                                                                                                                                                       5.95577547729739, 1.95187493704656, 1.53460547340489, 5.31312071910167,
                                                                                                                                                       0.360349112046273, 0.359106408685155, 2.47804278288829, 3.77398733519527,
                                                                                                                                                       -0.901935191769481, 0.451969971163404, -1.247881070758, -1.84333634407619,
                                                                                                                                                       -2.83038590542415, 0.358228260307488, 4.77109656940017, -2.2989389242835,
                                                                                                                                                       -4.51922839229714, -3.84425247400102, -4.26144140376353,
                                                                                                                                                       -0.927762031369026, 2.62830215527249, -1.04310438522205,
                                                                                                                                                       -6.49754170975519, 0.696878158779156, 0, 0, -7.49629679731099,
                                                                                                                                                       -13.438690932166, 2.53602937765768, -0.502091114290665, 1.16763178534034,
                                                                                                                                                       -3.20157004870736, 1.52930624774647, -1.01692473331578, -6.14768398796952,
                                                                                                                                                       -1.64387357702998, 0.32468500230152, 4.14845304149587, -18.5861461140956,
                                                                                                                                                       -3.46353874674732, 2.1787089618729, 0, -4.40603137611288,
                                                                                                                                                       -3.49504692401273, 2.5901069723708, -2.29894347710051, -2.83038136754643,
                                                                                                                                                       -0.479670873372777, 3.7740726913419, 15.4150552820808, -9.35257741140739,
                                                                                                                                                       -1.09529247811365, 5.56888099064008, -0.417548114616236,
                                                                                                                                                       2.27519130803371, 0.611612644613617, 0.607903293454882, -0.607903293454895,
                                                                                                                                                       -2.46925583803112, -1.68071107821019, -5.21858242080634,
                                                                                                                                                       -5.50597556158977, -0.236123740223734, -1.66874627371168,
                                                                                                                                                       0.240112807979635, 0, -0.722033770301404, -3.44008675208271,
                                                                                                                                                       -1.00507076359777, 1.25472273389923, -8.58785461067082, 3.20884793401961,
                                                                                                                                                       0, 3.10905240442747, 0, -8.23839070900674, -2.80915166313562,
                                                                                                                                                       -2.30558911440495, -2.0619646190398, -0.896820600871524,
                                                                                                                                                       0.896820600871529, 2.06196461903981, 6.76313815654013, 4.26734638516585,
                                                                                                                                                       -3.72388717467848, -0.27136621892726, -1.36797643227116,
                                                                                                                                                       -1.10807378747202, 0.278147951622491, 2.19790226812068, 2.15065432390387,
                                                                                                                                                       3.65574426609062, -2.59755065597488, 2.59755065597488, -1.55041540516258,
                                                                                                                                                       -3.17489743487715, -1.62601409942161, 0)), class = c("grouped_df",
                                                                                                                                                                                                            "tbl_df", "tbl", "data.frame"), row.names = c(NA, -100L), groups = structure(list(
                                                                                                                                                                                                              symbol = "RCL", .rows = structure(list(1:100), ptype = integer(0), class = c("vctrs_list_of",
                                                                                                                                                                                                                                                                                           "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
                                                                                                                                                                                                                                                                                           ), row.names = c(NA, -1L), .drop = TRUE))

library(ggplot2)
ggplot(stocks, aes(Returns))+
  geom_histogram()+
  facet_wrap(~symbol)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 1 rows containing non-finite values (stat_bin).

Created on 2023-05-23 with reprex v2.0.2

Nothing else fails, it's just the histogram, that's why I've issues haha

I understand that the histogram fails with whatever data set you are using for your full plot. But it does not fail with the smaller data set. I suggest that you find a small data set where the histogram does fail or you post your full data set somewhere for others to use. It is very hard to debug code if the error cannot be reproduced.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.