如何在R中绘制具有多个条件(6*2*3)的多条线

如何在R中绘制具有多个条件(6*2*3)的多条线,r,function,ggplot2,R,Function,Ggplot2,我正在尝试绘制此数据框,该数据框共有36行*第7列: 注: 刺激结束时有6个因素,分别为1、1.5、2、2.5、3、3.5 三是三个重复的条件: visbility =1 soundvolume=0 (visbility) visbility =0 soundvolume=1 (soundvolume) visbility = 0 soundvolume=0 (this sould be called blank or empty) 日期框名称:master\u all\u r.csv st

我正在尝试绘制此数据框,该数据框共有36行*第7列: 注:

刺激结束时有6个因素,分别为1、1.5、2、2.5、3、3.5

三是三个重复的条件:

visbility =1 soundvolume=0 (visbility)
visbility =0 soundvolume=1 (soundvolume)
visbility = 0 soundvolume=0 (this sould be called blank or empty)

日期框名称:master\u all\u r.csv

stim_ending_t visbility soundvolume Opening_text               m     sd coefVar
          <dbl>     <dbl>       <dbl> <chr>                  <dbl>  <dbl>   <dbl>
1             1         0           0 Now focus on the Image  1.70  1.14    0.670
2             1         0           0 Now focus on the Sound  1.57  0.794   0.504
3             1         0           1 Now focus on the Image  1.62  1.25    0.772
4             1         0           1 Now focus on the Sound  1.84  1.17    0.637
5             1         1           0 Now focus on the Image  3.19 17.2     5.38 
6             1         1           0 Now focus on the Sound  1.59  0.706   0.444 
但是得到了这个
警告信息:
名称标准化后的重复美学:
这就是我得到的结果

理想情况下,绘图应该是这样的,但有三条线 . 我发现了这些阴谋


如果您想下载excel文件,您可以在名称master\u all\r.csv下找到它

我相信您正在寻找这样的文件:

库(tidyvere)
图书馆(readr)
测试主机%
变异(可视性声音=情况)(
可视性==1和音量==0~“可视性”,
可视性==0和声音音量==1~“声音音量”,
可视性==0&soundvolume==0~“空”))%>%
变异率(可变值(可视性和声音),系数)%>%
ggplot(aes(x=刺激结束,y=m,颜色=可视性/声音))+
geom_线(aes(线型=可视性_声音))+
几何点()+
面_换行(~打开_文本)+
主题_极小值()
下面是发生的事情:

  • 使用一些简单的条件逻辑将列解析为单个列
  • 将新列转换为因子列
  • 使用新标记列设置的颜色弹出ggplot
  • 告诉
    geom_line
    将此列也用于线型
  • 使用
    facet\u wrap
    (也可以使用
    facet\u grid
    !)将其分为两个图
  • 将主题设置为更容易看到的内容;)
我相信您正在寻找这样的产品:

库(tidyvere)
图书馆(readr)
测试主机%
变异(可视性声音=情况)(
可视性==1和音量==0~“可视性”,
可视性==0和声音音量==1~“声音音量”,
可视性==0&soundvolume==0~“空”))%>%
变异率(可变值(可视性和声音),系数)%>%
ggplot(aes(x=刺激结束,y=m,颜色=可视性/声音))+
geom_线(aes(线型=可视性_声音))+
几何点()+
面_换行(~打开_文本)+
主题_极小值()
下面是发生的事情:

  • 使用一些简单的条件逻辑将列解析为单个列
  • 将新列转换为因子列
  • 使用新标记列设置的颜色弹出ggplot
  • 告诉
    geom_line
    将此列也用于线型
  • 使用
    facet\u wrap
    (也可以使用
    facet\u grid
    !)将其分为两个图
  • 将主题设置为更容易看到的内容;)
非常感谢您对Zafar的即时帮助。尽管我收到了这样一条警告消息:“有19条警告(使用warnings()查看)。”我不确定如何查看这些警告?您可以使用
warnings()
。记住向上投票,如果有帮助的话,将其标记为最佳答案;)已经做完了,再次谢谢。我做了警告(我的数据框):这是我得到的
1:在mutate_impl(.data,dots,caller_env()):不相等的因子级别:强制转换到cat中的字符错误(“1:在mutate_impl(.data,dots,caller_env()):\n不相等的因子级别:强制转换到字符”,:参数2(键入“list”)无法通过“cat”处理
哦,这只是意味着你有一些因素。转换为字符可以纠正这一点:)我非常感谢你的即时帮助@Zafar。尽管我收到了这样一条警告消息:“有19条警告(使用warnings()查看)。”我不确定如何查看这些警告?您可以使用
warnings()
。记住向上投票,如果有帮助的话,将其标记为最佳答案;)已经做完了,再次谢谢。我做了警告(我的数据框):这是我得到的
1:在mutate_impl(.data,dots,caller_env()):不相等的因子级别:强制转换到cat中的字符错误(“1:在mutate_impl(.data,dots,caller_env()):\n不相等的因子级别:强制转换到字符”,:参数2(键入“list”)“cat”无法处理此问题。
噢,这只是意味着您有一些因素。转换为字符可以纠正此问题:)
ggplot(test_master, aes(x=stim_ending_t, y=m, group=Opening_text, visbility, soundvolume)) +
geom_line(aes(linetype=Opening_text, visbility, soundvolume))+
geom_point()
library(tidyvere)
library(readr)

test_master <- read_csv("https://raw.githubusercontent.com/MohJumper/VisualAuditoryModality/master/master_all_r.csv")

test_master %>%
  mutate(visbility_sound = case_when(
           visbility == 1 & soundvolume == 0 ~ "visibility",
           visbility == 0 & soundvolume == 1 ~ "soundvolume",
           visbility == 0 & soundvolume == 0 ~ "empty")) %>% 
  mutate_at(vars(visbility_sound), factor) %>% 
  ggplot(aes(x = stim_ending_t, y = m, color = visbility_sound)) +
  geom_line(aes(linetype = visbility_sound)) +
  geom_point() +
  facet_wrap(~Opening_text) +
  theme_minimal()