且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ggplot2图例中使用下标[R]

更新时间:2023-11-26 13:01:04

以下应该有效(删除带有 names(temp) <-...)的行:

The following should work (remove your line with names(temp) <-...):

ggplot(temp.m, aes(x = value, linetype = variable)) + 
  geom_density() + facet_wrap(~ a) +    
  scale_linetype_discrete(breaks=levels(temp.m$variable),
                          labels=c(expression(b[1]), expression(c[1])))

请参阅 help(scale_linetype_discrete) 以了解可用的自定义(例如通过 name= 的图例标题).

See help(scale_linetype_discrete) for available customization (e.g. legend title via name=).