【问题标题】:How to set ggplot2 with two levels of color and three levels of linetype如何用两级颜色和三级线型设置ggplot2
【发布时间】:2014-10-07 08:52:05
【问题描述】:

我整个下午都在尝试,但仍然没有成功。 我有一个包含四个变量的数据框,就像这样,

       fpr tpr col lty
        0  0.000 red   a
        0  0.002 red   a
        0  0.004 red   a
        0  0.006 red   a
        0  0.008 red   a
        0  0.010 red   a 

前两列是我想用于绘图的。最后两列用于指定颜色和线型。我有三个级别的颜色,分别是“红色”、“蓝色”、“绿色”,以及两个级别的线型,分别是“a”和“d”(代表实线和虚线)。但是当我使用以下代码时

            ggplot() + scale_color_identity() + scale_linetype_identity()+
            geom_line( data=dataf, aes( x=fpr, y=tpr, colour=col, linetype=lty ))

我无法制作我想要的图(对不起,我目前没有资格上传图......) 谁能帮我解决这个问题?

【问题讨论】:

  • a 不是可识别的线型
  • 描述结果以及它们与您的期望或期望有何不同。
  • 提供图片链接,我们中的一个人可以编辑帖子并将其包含在内。
  • 为了扩展 baptiste 所说的,如果您不提供有效值,则不能使用身份量表。 linetype 必须是“实线”、“虚线”、“点线”等之一。

标签: r


【解决方案1】:

以下作品(去掉 scale_linetype_identity()):

ggplot() + scale_color_identity()+ geom_line( data=dataf, aes( x=fpr, y=tpr, colour=col, linetype=lty ))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-18
    • 2015-09-25
    • 1970-01-01
    • 2019-02-16
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    相关资源
    最近更新 更多