如何在R中划线的四条线中只有一条线?

时间:2016-02-29 13:47:24

标签: r graph ggplot2 statistics

我在这里面临一个问题。我应该创建一个由四条线组成的线图,其中一条线应该是虚线,而其他线则是连续的。我设法做到了:

plot with four lines]

尽管如此,这种方法的问题在于图例中没有出现图例。这是我的命令行:

library(dplyr)
library(ggplot2)

DF$Distractor <- factor(DF$Distractor, levels = c("NF", "LSF", "HSF", "MASK")) ## Rearrange modalities
DF %>%
  mutate(dummy = ifelse(Distractor  != "MASK", 0, 1)) %>% ## MASK dashed ##
  ggplot(aes(x = Lag, y = ., colour = Distractor, group = Distractor, linetype = dummy %>% as.factor())) +
  guides(linetype = FALSE) + ## Drop the dummy legend ##
  geom_line(size = .75) +
  scale_colour_grey() +
  theme_classic() +
  labs(x = "Lag", y = "Probability of T2 report") +
  ylim(0, 1)

以下是数据:

   Distractor  Lag         .
1          NF Lag1 0.4556818
2          NF Lag3 0.2113636
3          NF Lag8 0.4954545
4         LSF Lag1 0.4238636
5         LSF Lag3 0.2397727
6         LSF Lag8 0.5659091
7         HSF Lag1 0.4579545
8         HSF Lag3 0.3125000
9         HSF Lag8 0.4954545
10       MASK Lag1 0.4170455
11       MASK Lag3 0.2022727
12       MASK Lag8 0.4443182

是否有/另一种解决方案才能实现这一目标?我宁愿一个干净整洁的人,而不是一些棘手的技巧。

1 个答案:

答案 0 :(得分:0)

一种解决方案是在指南选项中添加Dim TotalSheets As Integer Dim p As Integer Dim iAnswer As VbMsgBoxResult With Application .DisplayAlerts = False .ScreenUpdating = False End With ' ' Move sheet "TOC" to the begining of the workbook. ' Sheets("TOC").Move Before:=Sheets(1) ' ' Move sheet "data" to be the second sheet in the workbook. ' Sheets("data").Move Before:=Sheets(2) iAnswer = MsgBox("You are about to copy data validations!", vbOKCancel + vbExclamation _ + vbDefaultButton2 + vbMsgBoxSetForeground, "Copying Data Valadations") For TotalSheets = 1 To Sheets.Count For p = 3 To Sheets.Count - 2 ' ' If the answer is Yes, then copy data validations from "TEMPLATE (Maint.) to all other. ' sheets minus the "TOC" sheet and the "data" sheet. ' If iAnswer = vbYes Then If UCase$(Sheets(p).Name) <> "TOC" And UCase$(Sheets(p).Name) <> "data" Then ' This chunk of code should copy only the data validations ' of "Table1_1" (A4:AO4) from the maintenance tab to all ' rows of a single table on each worksheet (minus the ' "TOC", "data", & the "TEMPLATE (Maint.)" worksheets. ' This is the section of code I am looking for unless ' someone has something better they can come up with. Selection.PasteSpecial Paste:=xlPasteValidation, _ Operation:=xlNone, SkipBlanks:=False, Transpose:=False End If ' ' If the answer is Cancel, then cancels. ' ElseIf iAnswer = vbCancel Then ' Add an exit here. End If With Application .DisplayAlerts = True .ScreenUpdating = True End With 。以下代码应该这样做:

override.aes

请注意在指南选项中添加颜色。我希望这会有所帮助。