提示如下:使用提供的SQL代码对一篮子商品进行分析,以提取特定商品对在同一篮子中出现的频率。 使用geom_tile()创建一个热图。 包括可以促进必要调整以使热图有用的代码。
我已经建立了连接,目前我的代码已经连接了
```{sql, connection = conn, output.var = "dataframe"}
SELECT (SELECT productName FROM Products WHERE Products.productCode = OD1.productCode) AS `Product 1`,
(SELECT productName FROM Products WHERE Products.productCode = OD2.productCode) AS `Product 2`, count(*) as Frequency
FROM OrderDetails AS OD1 JOIN OrderDetails AS OD2 ON OD1.orderNumber = OD2.orderNumber
WHERE OD1.productCode > OD2.productCode
GROUP BY `Product 1`, `Product 2` HAVING Frequency > 10
ORDER BY Frequency DESC, `Product 1`, `Product 2`;
```
```{r}
names(dataframe) <-c('Prod1', 'Prod2', 'Frequency')
ggplot(dataframe, aes(x=Prod1, Prod2, y=Frequency)) +
geom_tile(aes(fill=Frequency))+
scale_fill_gradient(name='Basket of Goods Analysis', low='white', high='red')
```
我坚持如何显示篮子中特定对的存在,因此将不胜感激!我还停留在提示的x值使用什么上。