如何基于 R (ggplot) 中的多个列值过滤基于和 facep_wrap

How to filter based and facep_wrap based on multiple column values in R (ggplot)

我正在处理一个数据集,想使用 ggplot geom_point 可视化“标题”列和 facet_wrap 中 5 个组中的两个组的数据,基于 "NewSess"和 "title"。到目前为止我已经写了:

ggplot(CMdata[CMdata$title == 'SAFARI', 'CHROME'], aes(x = Sales, y = Product.Views)) +
geom_point() +
facet_wrap(~NewSess, title)

ggplot 不允许我 facet_wrap 两个条件下的数据。

Sales   NewNess   title    Product.Views
 100       Y      SAFARI       822
 90        N      CHROME       962
 190       Y      CHROME       213
 190       N      SAFARI       332
 100       N        IE         329

有人能告诉我我做错了什么吗?

试试这个

ggplot(CMdata[CMdata$title %in% c('SAFARI','CHROME'),], aes(x = sales, y = Product.Views)) +
    geom_point() +
    facet_wrap(NewNess ~title)