【发布时间】:2018-08-02 03:24:00
【问题描述】:
我有一些我想绘制的整洁数据,将两列组合起来 分组。
在图例中,我想打印其中一列中的条目之一 大胆的脸。
这是一个最小的工作示例:
library(ggplot2)
plot.data <- data.frame(x=1:10, y=1:10,
class1=rep(letters[1:2], 10),
class2=rep(LETTERS[1:2], each=5))
# This class should be displayed in bold
# Might be subject to change; consider it a function parameter
class2.bold <- "A"
# This is the default
# Note that the used classes are automagically determined from the data
ggplot(plot.data, aes(x, y)) +
geom_point(aes(color=paste(class1, class2, sep="/"))) +
scale_color_discrete("class")
# This is what I want
# Note that it only works because I know the data used in this example
ggplot(plot.data, aes(x, y)) +
geom_point(aes(color=paste(class1, class2, sep=" / "))) +
scale_color_discrete("class",
label=c(expression(a / bold(A)),
expression(a / B),
expression(b / bold(A)),
expression(b / B)))
如何利用class2.bold 和plot.data 获得第二个情节
仅(即在编写代码时没有进一步了解其内容)?
例如,当我将class2.bold 更改为"B" 并将更多数据行添加到
plot.data 具有附加 class1 和 class2 值/组合,我
仍然希望 plot 命令无需手动调整即可工作。
【问题讨论】: