如何在R中制作有条件的GGPLOT?

发布于 2025-01-20 15:29:19 字数 381 浏览 1 评论 0原文

我有大约 40 个变量,所有产品。所有类别都是“是”或“否”。然后将它们链接到低、中或高的评级。

我的目标是制作每个标记为“是”的产品的评分的彩色散点图。

可重现的示例:

tab <- 矩阵(c('kmart',"y", "y", "n","low", 'target', "n", "n", "n","moderate" ,'bigw',"y","y","y","high"), ncol=5, byrow=TRUE)

colnames(tab) <- c('shop','dress','skirt','shoes',' rating')

我需要一个散点图,其 y 轴上有评级,根据产品着色。仅当类别部分中有“是”时,这些点才会显示。

谢谢你!

I have around 40 variables, all products. The categories for all are either yes or no. They then link up to a rating of either low, medium or high.

My aim is to make a colored scatterplot of the ratings of each of the products that are marked yes.

reproducible example:

tab <- matrix(c('kmart',"y", "y", "n","low", 'target', "n", "n", "n","moderate",'bigw',"y", "y", "y","high"), ncol=5, byrow=TRUE)

colnames(tab) <- c('shop','dress','skirt','shoes','rating')

I need a scatterplot with the rating on the y axis, coloured based on the product. the dots will only show up when there is a yes in the category section.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2025-01-27 15:29:19

你的意思是这样的吗?

library(ggplot2)
tab <- as.data.frame(tab)
m <- reshape2::melt(tab,id.vars=c("shop","rating"))
ggplot(m[m$value=="y",],aes(x=shop,y=rating,col=variable))+
  geom_point()

Do you mean something like this?

library(ggplot2)
tab <- as.data.frame(tab)
m <- reshape2::melt(tab,id.vars=c("shop","rating"))
ggplot(m[m$value=="y",],aes(x=shop,y=rating,col=variable))+
  geom_point()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文