我有一个包含三组的数据框。我必须按组和状态为某些指标绘制线条 ---- 这无法分面。所有线条必须一起出现在同一个图中。每个组将有一种线条颜色 - 和两条线 - 一根虚线和一根实线,基于 bool 状态,即,对于三个组,将有六条线。
类似的示例数据框:
Data <- data.frame(
groupname = sample(c("group1", "group2", "group3"), 100, replace = TRUE),
timeblock = sample(1:10, 100, replace = TRUE),
supermetric = sample(1:25, 100, replace = TRUE),
boolstatus = sample(0:1, 100, replace = TRUE) )
到目前为止,我没有成功地尝试过:基于组进行拆分并调用嵌套元素,以及尝试使用较小的数据帧创建各个层(这与所有融化数据的建议背道而驰)。 错误包括:
Error: Aesthetics must either be length one, or the same length as the dataProblems:group1df$supermetric
Error: ggplot2 doesn't know how to deal with data of class list
最佳答案
根据描述,我尝试了
ggplot(Data, aes(x=timeblock, y=supermetric,
group=interaction(boolstatus, groupname),
colour=groupname, linetype=factor(boolstatus))) +
geom_line()
但我不知道这是否是你想要的情节。
关于r - GGplot - 基于其他列的同一列值的多行 - 无方面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17180859/