使用 ggplot 绘制 ‘price’ 与 ‘carat’ 的散点图。要求:‘price’ 在 y 轴,‘carat’ 在 x 轴,点的颜色由 ‘cut’ 决定。
Make a scatter plot between ‘price’ and ‘carat’ using ggplot. ‘Price’ should be on y-axis, ‘carat’ should be on the x-axis, and the ‘color’ of the points should be determined by ‘cut.’
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: easy
分类: Data Visualization
标签: ggplot2, scatter-plot, diamonds
参考答案摘要
答案 我们将使用 ggplot 来实现散点图。 ggplot 基于数据可视化的语法(grammar of data visualization),可以让我们把多层(layers)叠加在一起。 因此,我们会先从数据层(data layer)开始,然后在其上叠加美学映射层(aesthetic layer)。最后,在美学层之上叠加几何对象层(geometry layer)。 代码: ggplot(dat...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。