R 如何在geom_point点图中仅显示前10个类别和值?
我想用点图来排列订购最多的产品,以降序显示它们的订购时间。但是有134个产品,所以点图被压扁了。所以我需要整理出图中的前10个产品,我如何编辑代码 以下是我的绘图数据:R 如何在geom_point点图中仅显示前10个类别和值?,r,sorting,ggplot2,R,Sorting,Ggplot2,我想用点图来排列订购最多的产品,以降序显示它们的订购时间。但是有134个产品,所以点图被压扁了。所以我需要整理出图中的前10个产品,我如何编辑代码 以下是我的绘图数据: head(product_count) product order_times frozen juice 2 baby bath body care 7 Indian foods 7 bea
head(product_count)
product order_times
frozen juice 2
baby bath body care 7
Indian foods 7
beauty 8
bulk grains rice dried goods 8
代码:
实际点打印有134行,但我只想显示10行(前10行)您可以使用
top\n
筛选前10个值,然后使用它在ggplot
对象中打印
library(dplyr)
library(ggplot2)
df %>%
top_n(10, order_times) %>%
ggplot() + aes(product, order_times) + geom_point()
或仅使用ggplot2
ggplot(df[tail(order(df$order_times), 10), ], ) +
aes(product, order_times) + geom_point()
类似于
df%%>%top\u n(10)%%>%ggplot()+aes(产品、订单时间)+geom\u point()
?产品计数中出现错误%>%top\u n(10)%%>%ggplot():找不到函数“%%>”,如果尚未安装,则需要执行库(dplyr)
或安装.packages(“dplyr”)
,啊哈,它成功了。非常棘手。
ggplot(df[tail(order(df$order_times), 10), ], ) +
aes(product, order_times) + geom_point()