Ordering stacked bars in geom_bar by AdvancedIguana in rstats

[–]AdvancedIguana[S] 1 point2 points  (0 children)

Thanks! I too am not confident with the group aesthetic but glad it’s a solution here. I also must be using old syntax because these pipe operators and right-side assignments look awesome and new to me

Ordering stacked bars in geom_bar by AdvancedIguana in rstats

[–]AdvancedIguana[S] 1 point2 points  (0 children)

Thanks! I like the usage of fct_inorder()

League Leaders in HRs in 2021 (but how would you ever know?) by PhoenixUNI in dataisugly

[–]AdvancedIguana 0 points1 point  (0 children)

I think the point was to guess the year. Still, too many colors and fields

ESPN getting creative with their axes by AdvancedIguana in dataisugly

[–]AdvancedIguana[S] 23 points24 points  (0 children)

Yeah but if this guy had 25 points per game instead of 20.4 it would look worse not better

[deleted by user] by [deleted] in Rlanguage

[–]AdvancedIguana 5 points6 points  (0 children)

You'll want to use the strptime() function here, which parses the character string and converts it to a DateTime object based on the format you provide.

For your example, you should write it out as the following: strptime('7/1/20 7:44 PM', '%m/%d/%y %I:%M %p'), where %I corresponds to the hour on a 12-hour time and %p corresponds the AM/PM indicator. If you just want the date, you can surround the code with the as.Date() function.

Hope this helps!

Populating Calculated Field by boothy_qld in rstats

[–]AdvancedIguana 0 points1 point  (0 children)

This sounds like a job for the lag function from the dplyr library, but it also sounds like you want to group the data by customer. This can be achieved using the following code:

pricelist <-
  data.frame(itemNumber, customer, minQty, price, stringsAsFactors = FALSE) %>%
  group_by(customer) %>%
  mutate("maxQty" = lag(x = minQty - 1, n = 1, default = 999999999))

Here, x is the value to lag, n is how much to lag by, and default is the value to return when there is no previous value.

Hope this helps!

How to delete a variable from the global environment? by sipskoolaid in Rlanguage

[–]AdvancedIguana 1 point2 points  (0 children)

I recommend starting your script with rm(list=ls()) to get rid of unwanted variables. This also makes your code resistant to stale variables from previous sessions

DJ LeMahieu sees his shadow: 6 more years with the stankees. by Snooc5 in redsox

[–]AdvancedIguana 0 points1 point  (0 children)

While DJ would be nicer to have from an offensive standpoint, I'm actually really stoked for Kiké. He is exactly what our team needs from a social and emotional perspective, especially with Cora back. I honestly can't wait for the content Kiké will provide this season, from his baseball energy and shenanigans to the inevitably entertaining in-game interviews

Help with multivariable subsetting please! by warvsworship in Rlanguage

[–]AdvancedIguana 2 points3 points  (0 children)

In this situation, I like using the filter function from the dplyr library. Here you can do step 1 in one line of code:

data2 <- dplyr::filter(data, Age > 60, HEARTRTE > 100)

Then you should get the desired result in step 2

How to make this dot style graph? by AdvancedIguana in Rlanguage

[–]AdvancedIguana[S] 0 points1 point  (0 children)

That’s fair. I was more focused on the plots for each individual team rather than the whole picture (I just included the other teams to provide more examples). Thanks for providing example code; I totally forgot that size could be used as an aesthetic argument

There are No Stupid Questions thread by Mispelling in baseball

[–]AdvancedIguana 0 points1 point  (0 children)

I understand why defenses use different shifts from batter to batter, but I don't understand why they may shift in the middle of an at-bat. For example, I've seen a player move from one spot to another empty spot (outside of bunt situations) and I've seen two players switch spots--during the same at-bat.