首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绘制折线图

绘制折线图
EN

Stack Overflow用户
提问于 2020-08-25 17:55:34
回答 1查看 34关注 0票数 2

我对R来说真的是个新手,我正在努力创建一个线条图。我想要有在x轴上的时间和在y轴上的百分比,并根据‘家庭,其他和孩子’变量为图形上色。我希望有2行,一行显示“其他活动或占用模式”的时间,另一行显示“活动:与母亲和孩子共度的时间;职业模式:在家,与配偶/伴侣和孩子在一起”的时间。我尝试在堆叠的条形图上添加一行,但是不起作用。

代码语言:javascript
复制
structure(list(time = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 
4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 
12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 
18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 
25L, 25L), .Label = c("04:00", "04:10", "04:20", "04:30", "04:40", 
"04:50", "05:00", "05:10", "05:20", "05:30", "05:40", "05:50", 
"06:00", "06:10", "06:20", "06:30", "06:40", "06:50", "07:00", 
"07:10", "07:20", "07:30", "07:40", "07:50", "08:00", "08:10", 
"08:20", "08:30", "08:40", "08:50", "09:00", "09:10", "09:20", 
"09:30", "09:40", "09:50", "10:00", "10:10", "10:20", "10:30", 
"10:40", "10:50", "11:00", "11:10", "11:20", "11:30", "11:40", 
"11:50", "12:00", "12:10", "12:20", "12:30", "12:40", "12:50", 
"13:00", "13:10", "13:20", "13:30", "13:40", "13:50", "14:00", 
"14:10", "14:20", "14:30", "14:40", "14:50", "15:00", "15:10", 
"15:20", "15:30", "15:40", "15:50", "16:00", "16:10", "16:20", 
"16:30", "16:40", "16:50", "17:00", "17:10", "17:20", "17:30", 
"17:40", "17:50", "18:00", "18:10", "18:20", "18:30", "18:40", 
"18:50", "19:00", "19:10", "19:20", "19:30", "19:40", "19:50", 
"20:00", "20:10", "20:20", "20:30", "20:40", "20:50", "21:00", 
"21:10", "21:20", "21:30", "21:40", "21:50", "22:00", "22:10", 
"22:20", "22:30", "22:40", "22:50", "23:00", "23:10", "23:20", 
"23:30", "23:40", "23:50", "00:00", "00:10", "00:20", "00:30", 
"00:40", "00:50", "01:00", "01:10", "01:20", "01:30", "01:40", 
"01:50", "02:00", "02:10", "02:20", "02:30", "02:40", "02:50", 
"03:00", "03:10", "03:20", "03:30", "03:40", "03:50"), class = "factor"), 
    homemotherandchild = c("Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern", "Activity: Time Spent with mother and child  ; Occupacy pattern: At home, with spouse/partner and child", 
    "Other activity or occupancy pattern"), n = c(706L, 196L, 
    713L, 189L, 712L, 190L, 711L, 191L, 710L, 192L, 707L, 195L, 
    709L, 193L, 706L, 196L, 701L, 201L, 693L, 209L, 693L, 209L, 
    689L, 213L, 683L, 219L, 676L, 226L, 669L, 233L, 653L, 249L, 
    642L, 260L, 625L, 277L, 599L, 303L, 597L, 305L, 576L, 326L, 
    547L, 355L, 528L, 374L, 510L, 392L, 475L, 427L), Percent = c(0.96978021978022, 
    0.269230769230769, 0.979395604395604, 0.259615384615385, 
    0.978021978021978, 0.260989010989011, 0.976648351648352, 
    0.262362637362637, 0.975274725274725, 0.263736263736264, 
    0.971153846153846, 0.267857142857143, 0.973901098901099, 
    0.26510989010989, 0.96978021978022, 0.269230769230769, 0.962912087912088, 
    0.276098901098901, 0.951923076923077, 0.287087912087912, 
    0.951923076923077, 0.287087912087912, 0.946428571428571, 
    0.292582417582418, 0.938186813186813, 0.300824175824176, 
    0.928571428571429, 0.31043956043956, 0.918956043956044, 0.320054945054945, 
    0.896978021978022, 0.342032967032967, 0.881868131868132, 
    0.357142857142857, 0.858516483516483, 0.380494505494505, 
    0.822802197802198, 0.416208791208791, 0.820054945054945, 
    0.418956043956044, 0.791208791208791, 0.447802197802198, 
    0.751373626373626, 0.487637362637363, 0.725274725274725, 
    0.513736263736264, 0.700549450549451, 0.538461538461538, 
    0.652472527472527, 0.586538461538462)), row.names = c(NA, 
-50L), class = c("tbl_df", "tbl", "data.frame"))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-25 18:29:14

为了便于理解,我建议采用下一步的ggplot2方法来安排元素。使用df作为您包含的dput()数据,下面是代码:

代码语言:javascript
复制
library(ggplot2)

ggplot(df,aes(x=time,y=Percent,group=homemotherandchild,color=homemotherandchild))+
  geom_line()+
  scale_y_continuous(labels = scales::percent)+
  theme_bw()+
  theme(legend.position = 'top')

输出:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63576349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档