{"id":101,"date":"2023-06-16T05:24:16","date_gmt":"2023-06-15T20:24:16","guid":{"rendered":"https:\/\/best-biostatistics.com\/toukei-er\/entry\/mean-line-chart-of-repeated-measures-by-ggplot-in-r\/"},"modified":"2025-01-14T22:55:21","modified_gmt":"2025-01-14T13:55:21","slug":"mean-line-chart-of-repeated-measures-by-ggplot-in-r","status":"publish","type":"post","link":"https:\/\/best-biostatistics.com\/toukei-er\/entry\/mean-line-chart-of-repeated-measures-by-ggplot-in-r\/","title":{"rendered":"R \u3067\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u304f\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u7fa4\u3054\u3068\u6642\u70b9\u3054\u3068\u306e\u5e73\u5747\u5024\u3092\u7d50\u3093\u3060\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u304f\u65b9\u6cd5<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u3068\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\">\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u3068\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5<\/h2>\n\n\n\n<p>\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u3068\u306f\u3001\u540c\u3058\u5bfe\u8c61\u8005\u304c\u3042\u308b\u6c7a\u307e\u3063\u305f\u6642\u70b9\u3067\u4f55\u56de\u304b\u6e2c\u5b9a\u3057\u305f\u30a2\u30a6\u30c8\u30ab\u30e0\u30c7\u30fc\u30bf\u306e\u3053\u3068\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306e\u3088\u3046\u306b\u30018, 10, 12, 14 \u6b73\u306e\u6642\u306e\u6e2c\u5b9a\u5024\u3068\u3044\u3063\u305f\u3088\u3046\u306a\u3001\u3042\u308b\u4e00\u5b9a\u671f\u9593\u306b\u7e70\u308a\u8fd4\u3057\u6e2c\u5b9a\u3057\u305f\u30c7\u30fc\u30bf\u3092\u6307\u3059<\/p>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3042\u3068\u306f\u3001\u6e2c\u5b9a\u6642\u70b9\u3054\u3068\u3001\u8208\u5473\u304c\u3042\u308b\u6bd4\u8f03\u7fa4\u3054\u3068\u306b\u5e73\u5747\u5024\u3092\u8a08\u7b97\u3057\u3066\u3001\u56f3\u793a\u3059\u308b\u306e\u304c\u304a\u3059\u3059\u3081\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306e\u50be\u5411\u304c\u898b\u3066\u53d6\u308c\u308b\u306e\u3067\u3001\u7d71\u8a08\u89e3\u6790\u7d50\u679c\u3092\u8aad\u307f\u53d6\u308b\u3068\u304d\u306b\u5f79\u306b\u7acb\u3064<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3068\u30b0\u30eb\u30fc\u30d7\u5225\u96c6\u8a08\">\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3068\u30b0\u30eb\u30fc\u30d7\u5225\u96c6\u8a08<\/h2>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u306f\u3001R \u306e nlme \u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b Orthodont \u3068\u3044\u3046\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u3053\u306e\u30c7\u30fc\u30bf\u306f\u3001\u7537\u5150 16 \u4f8b\u3068\u5973\u5150 13 \u4f8b\u306e 8, 10, 12, 14 \u6b73\u6642\u306e\u4e0b\u5782\u4f53\u304b\u3089\u7ffc\u4e0a\u984e\u88c2\u3068\u547c\u3070\u308c\u308b\u90e8\u5206\u307e\u3067\u306e\u8ddd\u96e2\u3092\u982d\u84cb\u9aa8\u306e X \u7dda\u64ae\u5f71\u50cf\u3067\u6e2c\u5b9a\u3057\u305f\u5024\u3067\u3042\u308b<\/p>\n\n\n\n<p>\u30c7\u30fc\u30bf\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7e26\u65b9\u5411\u306b\u7e70\u308a\u8fd4\u3057\u6e2c\u5b9a\u5024\u304c\u4e26\u3093\u3067\u3044\u308b\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u3042\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> head(Orthodont)\nGrouped Data: distance ~ age | Subject\n  distance age Subject  Sex\n1     26.0   8     M01 Male\n2     25.0  10     M01 Male\n3     29.0  12     M01 Male\n4     31.0  14     M01 Male\n5     21.5   8     M02 Male\n6     22.5  10     M02 Male<\/code><\/pre>\n\n\n\n<p>\u307e\u305a\u306f\u3001dplyr \u30d1\u30c3\u30b1\u30fc\u30b8\u306e group_by \u95a2\u6570\u3092\u4f7f\u3063\u3066\u3001\u6027\u5225\u30fb\u5e74\u9f62\u5225\u306e Distance \u306e\u5e73\u5747\u5024\u3001\u6a19\u6e96\u504f\u5dee\u3001n \u3092\u96c6\u8a08\u3059\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data('Orthodont', package = 'nlme')\nlibrary(dplyr)\ndf &lt;- Orthodont %>%\n  group_by(Sex, age) %>%\n  summarise(mean=mean(distance), sd=sd(distance), n=n())\ndf\n<\/code><\/pre>\n\n\n\n<p>\u96c6\u8a08\u3057\u305f\u7d50\u679c\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> df\n# A tibble: 8 \u00d7 5\n# Groups:   Sex &#91;2]\n  Sex      age  mean    sd     n\n  &lt;fct>  &lt;dbl> &lt;dbl> &lt;dbl> &lt;int>\n1 Male       8  22.9  2.45    16\n2 Male      10  23.8  2.14    16\n3 Male      12  25.7  2.65    16\n4 Male      14  27.5  2.09    16\n5 Female     8  21.2  2.12    11\n6 Female    10  22.2  1.90    11\n7 Female    12  23.1  2.36    11\n8 Female    14  24.1  2.44    11<\/code><\/pre>\n\n\n\n<div id=\"biost-3648503164\" class=\"biost- biost-entity-placement\"><p style=\"text-align: center;\"><span style=\"font-size: 20px;\"><strong><a href=\"https:\/\/best-biostatistics.com\/kmhl\">\uff1e\uff1e\u3082\u3046\u7d71\u8a08\u3067\u60a9\u3080\u306e\u306f\u7d42\u308f\u308a\u306b\u3057\u307e\u305b\u3093\u304b\uff1f\u00a0<\/a><\/strong><\/span><\/p>\r\n<a href=\"https:\/\/best-biostatistics.com\/kmhl\"><img class=\"aligncenter wp-image-2794 size-full\" src=\"https:\/\/best-biostatistics.com\/wp\/wp-content\/uploads\/2023\/11\/bn_r_03.png\" alt=\"\" width=\"500\" height=\"327\" \/><\/a>\r\n<p style=\"text-align: center;\"><span style=\"color: #ff0000; font-size: 20px;\"><strong><span class=\"marker2\">\u21911\u4e07\u4eba\u4ee5\u4e0a\u306e\u533b\u7642\u5f93\u4e8b\u8005\u304c\u8cfc\u8aad\u4e2d<\/span><\/strong><\/span><\/p><\/div><h2 class=\"wp-block-heading\" id=\"\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\">\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5<\/h2>\n\n\n\n<p>\u96c6\u8a08\u7d50\u679c\u3092\u4f7f\u3063\u3066\u3001\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u3044\u3066\u3044\u304f<\/p>\n\n\n\n<p>ggplot2 \u30d1\u30c3\u30b1\u30fc\u30b8\u306e ggplot() \u3092\u4f7f\u3063\u3066\u66f8\u304f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>library(ggplot2)\nggplot(data=df, aes(x=age, y=mean, group=Sex, linetype=Sex))+\n  geom_line(position=position_dodge(0.3))+\n  geom_point(size=3, position=position_dodge(0.3))+\n  geom_errorbar(aes(ymax=mean+sd, ymin=mean-sd), width=0.3,\n                position=position_dodge(0.3))+\n  labs(x='Age (years)', y='Distance')+\n  theme_classic()<\/code><\/pre>\n\n\n\n<p>data= \u306b\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u6307\u5b9a\u3057\u3001aes \u3067 X \u8ef8\u3068 Y \u8ef8\u3092\u6307\u5b9a\u3059\u308b<\/p>\n\n\n\n<p>linetype= \u3067\u6027\u5225\u3054\u3068\u306b\u7dda\u7a2e\u3092\u5206\u3051\u308b<\/p>\n\n\n\n<p>geom_line() \u3067\u6298\u308c\u7dda\u3092\u66f8\u304d\u3001geom_point() \u3067\u5e73\u5747\u5024\u3092\u70b9\u3067\u63cf\u753b\u3059\u308b<\/p>\n\n\n\n<p>geom_errorbar() \u304c\u30a8\u30e9\u30fc\u30d0\u30fc\u3067\u3001\u5e73\u5747\u306b\uff0b\u3082\u3057\u304f\u306f\u30fc \u306e\u6a19\u6e96\u504f\u5dee\u3068\u3057\u3066\u3044\u308b<\/p>\n\n\n\n<p>\u3044\u305a\u308c\u306b\u3082 position=position_dodge(0.3) \u304c\u30aa\u30d7\u30b7\u30e7\u30f3\u3068\u3057\u3066\u66f8\u304b\u308c\u3066\u3044\u308b<\/p>\n\n\n\n<p>\u3053\u308c\u306f\u3001\u6027\u5225\u3054\u3068\u306b\u66f8\u3044\u305f\u7dda\u3084\u70b9\u3092\u5c11\u3057\u3060\u3051\u305a\u3089\u3059\uff08\u305d\u306e\u5e45\u306f 0.3 \u3067\u6307\u5b9a\uff09\u6307\u793a\u3067\u3042\u308b<\/p>\n\n\n\n<p>labs() \u304c\u8ef8\u306e\u30e9\u30d9\u30eb\u6307\u5b9a\u3067\u3001\u6700\u5f8c\u306b theme_classic() \u304c\u53e4\u5178\u7684\u306a\u30b9\u30bf\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u3044\u3066\u3001\u8ad6\u6587\u7b49\u5b66\u8853\u7684\u306a\u76ee\u7684\u306b\u306f\u9069\u5207\u306a\u898b\u305f\u76ee\u306b\u306a\u308b<\/p>\n\n\n\n<p>\u56f3\u306b\u3057\u3066\u307f\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"640\" height=\"640\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/06\/20230615223108.png\" alt=\"\" class=\"wp-image-972\" title=\"\" srcset=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/06\/20230615223108.png 640w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/06\/20230615223108-300x300.png 300w, https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/06\/20230615223108-150x150.png 150w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><span itemscope=\"\" itemtype=\"http:\/\/schema.org\/Photograph\"><\/span><\/p>\n\n\n\n<p>\u3053\u3093\u306a\u3075\u3046\u306b\u3059\u308b\u3068\u69d8\u5b50\u304c\u4e00\u76ee\u3067\u308f\u304b\u308b<\/p>\n\n\n\n<p>\u5e74\u9f62\u304c\u4e0a\u304c\u308b\u306b\u3064\u308c\u3066\u3001\u7537\u5973\u3068\u3082 Distance \u306f\u5927\u304d\u304f\u306a\u308a\u3001\u5973\u5150\u306b\u6bd4\u3079\u7537\u5150\u306e\u307b\u3046\u304c\u5927\u304d\u3044\u3053\u3068\u304c\u308f\u304b\u308b<\/p>\n\n\n\n<p>\u3053\u308c\u304c\u308f\u304b\u3063\u305f\u4e0a\u3067\u3001\u7dda\u5f62\u6df7\u5408\u30e2\u30c7\u30eb\u306a\u3069\u306e\u89e3\u6790\u3092\u884c\u3063\u3066\u3044\u304f\u3068\u3001\u7d50\u679c\u3092\u6b63\u3057\u304f\u89e3\u91c8\u3067\u304d\u308b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u307e\u3068\u3081\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>R \u3067 ggplot \u3092\u4f7f\u3063\u3066\u3001\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u3044\u3066\u307f\u305f<\/p>\n\n\n\n<p>\u53c2\u8003\u306b\u306a\u308c\u3070<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u95a2\u9023\u8a18\u4e8b\">\u95a2\u9023\u8a18\u4e8b<\/h2>\n\n\n<div class=\"swell-block-postLink\">\t\t\t<div class=\"p-blogCard -internal\" data-type=\"type1\" data-onclick=\"clickLink\">\n\t\t\t\t<div class=\"p-blogCard__inner\">\n\t\t\t\t\t<span class=\"p-blogCard__caption\">\u3042\u308f\u305b\u3066\u8aad\u307f\u305f\u3044<\/span>\n\t\t\t\t\t<div class=\"p-blogCard__thumb c-postThumb\"><figure class=\"c-postThumb__figure\"><img decoding=\"async\" src=\"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2022\/06\/20230205131645-300x300.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" width=\"320\" height=\"180\"><\/figure><\/div>\t\t\t\t\t<div class=\"p-blogCard__body\">\n\t\t\t\t\t\t<a class=\"p-blogCard__title\" href=\"https:\/\/best-biostatistics.com\/toukei-er\/entry\/line-graph-of-mean-and-error-bars-of-repeated-measure-with-ggplot2\/\">EZR \u3068 R \u306e ggplot \u3067\u30a8\u30e9\u30fc\u30d0\u30fc\u4ed8\u304d\u306e\u5e73\u5747\u5024\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u304f\u65b9\u6cd5<\/a>\n\t\t\t\t\t\t<span class=\"p-blogCard__excerpt\">ggplot2 \u3068\u3044\u3046\u30b0\u30e9\u30d5\u3092\u304d\u308c\u3044\u306b\u63cf\u753b\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u3001\u30a8\u30e9\u30fc\u30d0\u30fc\u4ed8\u304d\u306e\u5e73\u5747\u5024\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u63cf\u304f\u65b9\u6cd5\u3092\u7d39\u4ecb\u3059\u308b\u3002 \u53cd\u5fa9\u6e2c\u5b9a\u3057\u305f\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u5e73\u5747\u5024\u3068\u3001SD&#8230;<\/span>\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>\u53cd\u5fa9\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u7fa4\u3054\u3068\u6642\u70b9\u3054\u3068\u306e\u5e73\u5747\u5024\u3092\u7d50\u3093\u3060\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3092\u66f8\u304f\u65b9\u6cd5<\/p>\n","protected":false},"author":2,"featured_media":972,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[43,5,37],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ggplot2","category-r","category-37"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/best-biostatistics.com\/toukei-er\/wp-content\/uploads\/2023\/06\/20230615223108.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":2,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":3419,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/posts\/101\/revisions\/3419"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media\/972"}],"wp:attachment":[{"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/best-biostatistics.com\/toukei-er\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}