jak123
January 27, 2022, 12:24pm
1
Hi R com.
I have this piece of code:
Distribution of sales pr. salesId
df1 %>%
group_by(ItemId) %>%
mutate(SalesAmount = SalesPrice*SalesQty) %>%
summarize(sum_sale = sum(SalesAmount, na.rm = TRUE)) %>%
ggplot() +
geom_bar(aes(x = reorder(ItemId, sum_sale, FUN = desc),
y = sum_sale), stat = "identity") +
theme_bw() +
xlab("ItemID") +
ylab("Sum Sales")
But i have like 1000+ products and all i want is to look at the top 10 ItemId, the reorder function is not really helping me here unless there is a cool way of taking the top 10 Itemid based on SalesAmount and sort them. Any ideas?
df1 %>%
group_by(SalesId) %>%
mutate(SalesAmount = SalesPrice*SalesQty) %>%
summarize(sum_sale = sum(SalesAmount, na.rm = TRUE)) %>%
arrange(-SalesAmount) %>%
head(10)
1 Like
jak123
January 27, 2022, 8:44pm
3
Hi arthur.t
df1 %>%
group_by(SalesId) %>%
mutate(SalesAmount = SalesPrice*SalesQty) %>%
summarize(sum_sale = sum(SalesAmount, na.rm = TRUE)) %>%
arrange(-SalesAmount) %>%
head(10)
gives the error :
Error: arrange() failed at implicit mutate() step.
Problem with mutate()
column ..1
.
i ..1 = -SalesAmount
.
x object 'SalesAmount' not found
jak123
January 28, 2022, 7:50am
4
what does that mean?? SalesAmount is a column in the df
jak123
January 28, 2022, 7:58am
5
Have corrected the original post. And just to summarize: what i am interested in is seeing the top 10 itemID based on the total sales
system
Closed
February 4, 2022, 7:58am
6
This topic was automatically closed 7 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.