<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ドクターフント(Dr. Hund)</title>
	<atom:link href="https://brain-storm.space/feed/" rel="self" type="application/rss+xml" />
	<link>https://brain-storm.space</link>
	<description>脳や研究について発信するブログです。This site is for research and statistics.</description>
	<lastBuildDate>Fri, 24 Mar 2023 17:13:38 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://brain-storm.space/wp-content/uploads/2021/04/cropped-3d0209af428738b78799159b4ce75ad9-32x32.png</url>
	<title>ドクターフント(Dr. Hund)</title>
	<link>https://brain-storm.space</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[R beginners] Drawing ROC curve</title>
		<link>https://brain-storm.space/roc-curve-en/1304/</link>
					<comments>https://brain-storm.space/roc-curve-en/1304/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Sat, 25 Mar 2023 07:00:00 +0000</pubDate>
				<category><![CDATA[Statistical Analysis]]></category>
		<category><![CDATA[pROC]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[ROC]]></category>
		<category><![CDATA[sensitivity]]></category>
		<category><![CDATA[specificity]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1304</guid>

					<description><![CDATA[I will introduce how to draw an ROC curve. In R, it is very easy to draw an ROC curve. There are many librarie]]></description>
										<content:encoded><![CDATA[
<p>I will introduce how to draw an ROC curve. In R, it is very easy to draw an ROC curve. There are many libraries available for drawing ROC curves, but this time I will introduce how to draw it using the pROC library, which is commonly used and easy to use.</p>



<h3 id="rtoc-1" >Creating Sample Data</h3>



<p>This section is about creating sample data. If you don&#8217;t need it, please skip to the next section. Let&#8217;s consider how well we can detect people with the disease using two assays, &#8220;assay1&#8221; and &#8220;assay2&#8221;.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
set.seed(3)
condition &lt;- rep(c(&quot;healthy&quot;, &quot;disease&quot;), each = 50)
assay1 &lt;- c(rnorm(40, mean = 1, sd = 2), 
            rnorm(10, mean = 3, sd = 1), 
            rnorm(40, mean = 5, sd = 2), 
            rnorm(10, mean = 7, sd = 1))
assay2 &lt;- c(rnorm(30, mean = 1, sd = 3), 
            rnorm(20, mean = 2, sd = 2), 
            rnorm(30, mean = 3, sd = 3), 
            rnorm(20, mean = 4, sd = 2))

df = data.frame(condition, assay1, assay2)
</pre></div>


<p>these distributions would look like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
library(beeswarm)
beeswarm(data = df, assay1 ~ condition, 
         col = c(&quot;red&quot;,&quot;blue&quot;), pch=19)
beeswarm(data = df, assay2 ~ condition,
         col = c(&quot;red&quot;, &quot;blue&quot;), pch=19)
</pre></div>


<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/dotplot_assay1.jpeg" alt="" class="wp-image-1220" width="400" height="400"/><figcaption class="wp-element-caption">Assay1</figcaption></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/dotplot_assay2.jpeg" alt="" class="wp-image-1221" width="400" height="400"/><figcaption class="wp-element-caption">Assay2</figcaption></figure>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1304" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-1">Creating Sample Data</a></li><li class="rtoc-item"><a href="#rtoc-2">Use pROC</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3">Install pROC package</a></li><li class="rtoc-item"><a href="#rtoc-4">To draw a single ROC curve</a></li><li class="rtoc-item"><a href="#rtoc-5">Convert to Percentage Display</a></li><li class="rtoc-item"><a href="#rtoc-6">Display Confidence Interval of Sensitivity</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-7">Display Optimal Cutoff Point</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-8">display Optimal Cutoff based on Youden Index</a></li><li class="rtoc-item"><a href="#rtoc-9">Display Optimal Cutoff using Top Left Method</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-10">Extracting Necessary Values</a></li><li class="rtoc-item"><a href="#rtoc-11">Comparing two ROC curves by overlapping them</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-12">Overlay Two ROC Curves</a></li><li class="rtoc-item"><a href="#rtoc-13">Compare Two Assays</a></li></ul></li></ol></div><h2 id="rtoc-2" >Use pROC</h2>



<h3 id="rtoc-3" >Install pROC package</h3>



<p>First, you need to install and load the pROC package to use it in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
install.packages(&quot;pROC&quot;)
library(pROC)
</pre></div>


<h3 id="rtoc-4" >To draw a single ROC curve</h3>



<p>The data frame looks like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; head(df)
  condition     assay1     assay2
1   healthy -0.9238668  2.8520501
2   healthy  0.4149486 -0.2152325
3   healthy  1.5175764  4.1593113
4   healthy -1.3042638  2.8068527
5   healthy  1.3915657  4.0523835
6   healthy  1.0602479  2.8245020
</pre></div>


<p>There are several ways to proceed from here, but first let&#8217;s use roc() to store the result in an object.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
</pre></div>


<p>As an alternative, you can also use the following notation with &#8220;~&#8221;:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(df$condition ~ df$assay1, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
</pre></div>


<p>The <code>condition</code> column can be 0 and 1, as it is a binary variable. <code>ci</code> refers to the confidence interval.</p>



<p>you can use the <code>plot()</code> function to draw the ROC curve.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_1.jpeg" alt="" class="wp-image-1224"/><figcaption class="wp-element-caption">Assay1</figcaption></figure>



<h3 id="rtoc-5" >Convert to Percentage Display</h3>



<p>You can customize the axis to display in percentage format by adding <code>percent=TRUE</code>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, percent=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
plot(roc1)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_plot2_percent.jpeg" alt="" class="wp-image-1225"/></figure>



<h3 id="rtoc-6" >Display Confidence Interval of Sensitivity</h3>



<p>You can display the confidence interval of the sensitivity. To calculate the confidence interval of sensitivity, use <code>ci.se()</code>. <code>col</code> is used to specify the color.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
plot(roc2)
rocCI &lt;- ci.se(roc2)
plot(rocCI, type=&quot;shape&quot;, col=&quot;lightblue&quot;)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_ci_3.jpeg" alt="" class="wp-image-1227"/></figure>



<h2 id="rtoc-7" >Display Optimal Cutoff Point</h2>



<p>One important aspect of the ROC curve is determining the optimal cut-off point. While determining the optimal cut-off point is a big topic on its own, here we introduce two methods: the Youden Index and top left.</p>



<p>To explain briefly, the Youden Index is calculated as &#8220;sensitivity + specificity &#8211; 1&#8221;, and the point with the highest value is selected as the optimal cut-off point. On the other hand, the top left method extracts the point closest to the upper left corner of the ROC curve.</p>



<h3 id="rtoc-8" >display Optimal Cutoff based on Youden Index</h3>



<p>You can add the optimal cutoff to the plot by modifying the <code>plot()</code> function call. Setting <code>print.thres = "best"</code> and <code>print.thres.best.method = "youden"</code> will display the optimal point. Setting <code>legacy.axes = TRUE</code> will make the x-axis display as 1-Specificity.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1, main = &quot;ROC Curve&quot;,      
     identity = TRUE,
     print.thres = &quot;best&quot;,
     print.thres.best.method = &quot;youden&quot;,
     legacy.axes = TRUE)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_youden_5.jpeg" alt="" class="wp-image-1231"/><figcaption class="wp-element-caption">optimal cutoff using the Youden Index (J = Sensitivity + Specificity &#8211; 1)</figcaption></figure>



<p>The optimal cut-off point in this case is 3.912 with sensitivity of 0.820 and specificity of 0.960.</p>



<h3 id="rtoc-9" >Display Optimal Cutoff using Top Left Method</h3>



<p>In the case of top left, set <code>print.thres.best.method="closest.topleft"</code> in <code>plot()</code> function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1, main = &quot;ROC Curve&quot;,      
     identity = TRUE,
     print.thres = &quot;best&quot;,
     print.thres.best.method = &quot;closest.topleft&quot;
     legacy.axes = TRUE)

</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_topleft_4.jpeg" alt="" class="wp-image-1234"/><figcaption class="wp-element-caption">The optimal cutoff based on the top left approach</figcaption></figure>



<p>Note that in this case, the optimal cutoff is 3.365, with a sensitivity of 0.860 and specificity of 0.880.</p>



<h2 id="rtoc-10" >Extracting Necessary Values</h2>



<p>When presenting or publishing the values of AUC (area under the curve), sensitivity, specificity, etc., you can display them as follows.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; auc(roc1)
Area under the curve: 0.9536

# youden
&gt; coords(roc1, &quot;best&quot;, ret=c(&quot;threshold&quot;, &quot;sens&quot;, &quot;spec&quot;, &quot;ppv&quot;, &quot;npv&quot;))
          threshold sensitivity specificity       ppv       npv
threshold  3.912407        0.82        0.96 0.9534884 0.8421053

# topleft
&gt; coords(roc1, &quot;best&quot;, best.method=&quot;closest.topleft&quot;,　ret=c(&quot;threshold&quot;, &quot;sens&quot;, &quot;spec&quot;, &quot;ppv&quot;, &quot;npv&quot;))
          threshold sensitivity specificity      ppv       npv
threshold  3.364778        0.86        0.88 0.877551 0.8627451
</pre></div>


<h2 id="rtoc-11" >Comparing two ROC curves by overlapping them</h2>



<p>We have created sample data assuming two tests. Let&#8217;s see which test is better by comparing the two ROC curves.</p>



<h3 id="rtoc-12" >Overlay Two ROC Curves</h3>



<p>When overlapping two ROC curves, you can use the <code>lines()</code> function for the one that you want to add later, or simply use <code>plot(..., add=TRUE)</code> for the second curve. You can specify the color using <code>col</code>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
# Use roc() to create objects for the two assays
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

# Use lines()
obj1 &lt;- plot(roc1,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)

# Use add = TRUE
obj1 &lt;- plot(roc1,
             col=&quot;red&quot;)
obj2 &lt;- plot(roc2,
             col=&quot;blue&quot;,
             add=TRUE)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_two_assay_6.jpeg" alt="" class="wp-image-1239"/></figure>



<h3 id="rtoc-13" >Compare Two Assays</h3>



<p>o compare two assays, use <code>roc.test()</code>. By default, it compares the AUCs (area under the curve) using the DeLong method, but you can change it to the bootstrap method by specifying <code>method = "bootstrap"</code>. The p-value is displayed in the center using text(). You can also specify the title using <code>main=</code>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

obj1 &lt;- plot(roc1,
             main=&quot;Comparison&quot;,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)
obj &lt;- roc.test(obj1, obj2)
text(.5, .5, labels=paste(&quot;p-value =&quot;, format.pval(obj$p.value, 3)), 
     adj=c(0, .5))
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_7.jpeg" alt="" class="wp-image-1242"/></figure>



<p>If you just want to see the comparison results, <code>roc.test()</code> will provide you with the results.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; roc.test(roc1, roc2)

	DeLong's test for two correlated ROC curves

data:  roc1 and roc2
Z = 3.7621, p-value = 0.0001685
alternative hypothesis: true difference in AUC is not equal to 0
95 percent confidence interval:
 0.0969536 0.3078464
sample estimates:
AUC of roc1 AUC of roc2 
     0.9536      0.7512 
</pre></div>


<p>Finally, let&#8217;s add a legend.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

obj1 &lt;- plot(roc1,
             main=&quot;Comparison&quot;,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)

obj &lt;- roc.test(obj1, obj2)

# p values in the graph
text(.5, .5, labels=paste(&quot;p-value =&quot;, format.pval(obj$p.value, 3)), 
     adj=c(0, .5))

#legend
legend(&quot;bottomright&quot;, legend=c(&quot;Assay1&quot;, &quot;Assay2&quot;),
       col=c(&quot;red&quot;, &quot;blue&quot;), lty=1, lwd=2)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_final_8-1.jpeg" alt="" class="wp-image-1251"/></figure>



<p>That was a helpful tutorial on how to draw ROC curves in R using the pROC package. Thank you for sharing!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/roc-curve-en/1304/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[R for beginners] Creating Error Bars for Bar Graphs and Line Graphs in ggplot2</title>
		<link>https://brain-storm.space/error-bar-en/1291/</link>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 13:13:56 +0000</pubDate>
				<category><![CDATA[Statistical Analysis]]></category>
		<category><![CDATA[bar graph]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[error bar]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[tidyverse]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1291</guid>

					<description><![CDATA[The #8216;T#8217; symbol on bar graphs and line graphs represents error bars that extend above and below the]]></description>
										<content:encoded><![CDATA[
<p>The &#8216;T&#8217; symbol on bar graphs and line graphs represents error bars that extend above and below the data point, indicating standard error or standard deviation. Adding error bars in R&#8217;s ggplot2 is easy. Here&#8217;s a step-by-step guide:</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1291" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">Preparing the Data</a></li><li class="rtoc-item"><a href="#rtoc-2">Calculating the Mean, Standard Deviation, and Standard Error of the Data</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3">Use group_by and summarise_all functions in dplyr to Calculate</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-4">Drawing Error Bars in Bar Graphs</a></li><li class="rtoc-item"><a href="#rtoc-5">Drawing Error Bars on a Line Graph</a></li><li class="rtoc-item"><a href="#rtoc-6">Adding Error Bars to Grouped Data</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">Adding Error Bars to Grouped Bar Graphs</a></li><li class="rtoc-item"><a href="#rtoc-8">Drawing Error Bars on a Grouped Line Graph</a></li></ul></li></ol></div><h2 id="rtoc-1" >Preparing the Data</h2>



<p>We&#8217;ll be using tidyverse for this. If you have your own data, skip ahead.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
# Set working directory
setwd(&quot;~/Rpractice/&quot;)

# Load tidyverse
library(tidyverse)

# Generate random data
dat &lt;- list(
  X &lt;- rnorm(50, 30, 10),
  Y &lt;- rnorm(50, 50, 5),
  Z &lt;- rnorm(50, 40, 15)
)
df &lt;- data.frame(matrix(unlist(dat), nrow=50))
colnames(df) &lt;- c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;)

# Transform the data from wide to long
df.long &lt;- pivot_longer(df, cols = A:C, 
                        names_to = &quot;Categories&quot;, 
                        values_to = &quot;Values&quot;)
</pre></div>


<p>Now we have data that looks like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; head(df.long)
# A tibble: 6 x 2
  Categories Values
  &lt;chr&gt;       &lt;dbl&gt;
1 A            26.8
2 B            53.7
3 C            27.3
4 A            31.0
5 B            58.7
6 C            56.2
&gt; 
</pre></div>


<p>To add error bars to bar graphs and line graphs, you need the mean and standard error (or standard deviation) of the data. We use pivot_longer to transform the data from wide to long format.&#8221;</p>



<h2 id="rtoc-2" >Calculating the Mean, Standard Deviation, and Standard Error of the Data</h2>



<p>To add error bars, we need to calculate the mean, standard deviation, and standard error. If you already have this data, you can skip this section.</p>



<p>Calculating these values is easy with the dplyr package in tidyverse.</p>



<h3 id="rtoc-3" >Use group_by and summarise_all functions in dplyr to Calculate</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
a &lt;- group_by(df.long, Categories) %&gt;% 
  summarise_all(list(mean = ~mean(.), 
                     sd = ~sd(.), 
                     se = ~sd(.)/sqrt(length(.))))

</pre></div>


<p>We can simplify this code further,</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
a &lt;- group_by(df.long, Categories) %&gt;% 
  summarise_all(list(mean = mean, 
                     sd = sd, 
                     se = ~sd/sqrt(length(.))))

</pre></div>


<p>Let&#8217;s take a look at the data for &#8216;a&#8217;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; a
# A tibble: 3 x 4
  Categories  mean    sd    se
  &lt;chr&gt;      &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
1 A           30.1  9.93 1.40 
2 B           49.2  5.00 0.708
3 C           43.9 15.5  2.20 
</pre></div>


<p>We have generated a distribution that looks like this. Since the data was generated randomly, the values may vary slightly if you follow the same steps.</p>



<h2 id="rtoc-4" >Drawing Error Bars in Bar Graphs</h2>



<p>We will use the calculated data to create a bar graph and specify the error bars using <code><span class="marker">geom_errorbar()</span></code>. First, let&#8217;s specify only <code>ymin</code> and <code>ymax</code> in <code>geom_errorbar()</code> and take a look at the graph.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean, fill = Categories))+
  geom_bar(stat = &quot;identity&quot;) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se))

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar1-1024x614.jpg" alt="" class="wp-image-905" width="512" height="307"/></figure>



<p>The width is too wide. Let&#8217;s adjust it using the <code>width</code> argument. We will narrow both the bar graph and error bars.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean, fill = Categories))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1)

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar2-1024x614.jpg" alt="" class="wp-image-906" width="512" height="307"/></figure>



<p>It&#8217;s a good to adjust the width according to the size of the output image.</p>



<h2 id="rtoc-5" >Drawing Error Bars on a Line Graph</h2>



<p>The process for adding error bars to a line graph is the same as above. First, draw the line graph and then add <code>geom_errorbar()</code>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean)) +
  geom_line(group = 1) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar3-1024x614.jpg" alt="" class="wp-image-907" width="512" height="307"/></figure>



<h2 id="rtoc-6" >Adding Error Bars to Grouped Data</h2>



<p>Let&#8217;s generate grouped data.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&lt;pre class=&quot;wp-block-syntaxhighlighter-code&quot;&gt;# Add ID column
data &lt;- df.long %&gt;% 
  tibble::rownames_to_column(var = &quot;ID&quot;)

# Convert ID from character to numeric
data$ID &lt;- as.numeric(data$ID)

# Assign 1 to ID &lt;= 75 and 0 to ID &gt;= 76 to create the &quot;group&quot; column
data &lt;- mutate(data, group = ifelse(ID &lt; 76, 1, 0))

# Calculate Mean, SD, and SE
b &lt;- group_by(data, group, Categories) %&gt;% 
  summarise_at(vars(Values), list(mean = ~mean(.), 
                     sd = ~sd(.), 
                     se = ~sd(.)/sqrt(length(.))))

# Convert group column values from numeric to character
b$group &lt;- as.character(b$group)

# Check the data included in b
&gt; head(b)
# A tibble: 6 x 5
# Groups:   group &lt;img class=&quot;ranking-number&quot; src=&quot;https://brain-storm.space/wp-content/themes/jin/img/rank02.png&quot; /&gt;
  group Categories  mean    sd    se
  &lt;chr&gt; &lt;chr&gt;      &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
1 0     A           31.4 11.1  2.21 
2 0     B           51.0  4.31 0.862
3 0     C           33.9 13.5  2.70 
4 1     A           29.5 10.4  2.08 
5 1     B           49.5  4.02 0.804
6 1     C           36.5 15.8  3.16 
&gt; &lt;/pre&gt;
</pre></div>


<p>Now that we have grouped data, let&#8217;s draw a bar graph with error bars.</p>



<h3 id="rtoc-7" >Adding Error Bars to Grouped Bar Graphs</h3>



<p>By specifying <code>position = "dodge"</code>, you can create a grouped bar chart like this.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar4-1024x614.jpg" alt="" class="wp-image-909" width="512" height="307"/></figure>



<p>Let&#8217;s add error bars to this plot.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;)+
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), 
                    position = &quot;dodge&quot;, width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar5-1024x614.jpg" alt="" class="wp-image-910" width="512" height="307"/></figure>



<p>It is shifted to the center. You can adjust the position with <span class="marker"><code>position = position_dodge()</code></span>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group)) +
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                position = position_dodge(0.6), width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar6-1024x614.jpg" alt="" class="wp-image-911" width="512" height="307"/></figure>



<p>You&#8217;ve created a nice bar graph!</p>



<h3 id="rtoc-8" >Drawing Error Bars on a Grouped Line Graph</h3>



<p>The same can be done for a grouped line graph as well.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_line() +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar7-1024x614.jpg" alt="" class="wp-image-913" width="512" height="307"/></figure>



<p>The error bars are on top and overlapping, making it difficult to see. Let&#8217;s move <span class="marker">the error bars to the back first</span>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;) +
  geom_line() +
  geom_point(size = 3)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar8-1024x614.jpg" alt="" class="wp-image-914" width="512" height="307"/></figure>



<p>By <span class="marker">shifting the position to the left or right</span> using <code>position_dodge()</code>, overlapping of error bars can be avoided.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;, position = position_dodge(.2)) +
  geom_line(position = position_dodge(.2)) +
  geom_point(size = 3, position = position_dodge(.2))

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar10-1024x614.jpg" alt="" class="wp-image-915" width="512" height="307"/></figure>



<p>Now you can add error bars to line graphs. I hope this was helpful.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>R, ggplot2を使った論文に使えるグラフテクニック【まとめ】</title>
		<link>https://brain-storm.space/r_graph/962/</link>
					<comments>https://brain-storm.space/r_graph/962/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 12:25:12 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=962</guid>

					<description><![CDATA[Rではキレイなビジュアルのグラフを無料で作ることができます。高いソフトウェアは不要で、論文に十分使える図ができます！特にggplot2はその使いやすさや見た目のキレイさからとても好評です。 様々なデータがあると思いますが]]></description>
										<content:encoded><![CDATA[
<p>Rではキレイなビジュアルのグラフを<span class="marker">無料で</span>作ることができます。高いソフトウェアは不要で、論文に十分使える図ができます！特にggplot2はその使いやすさや見た目のキレイさからとても好評です。</p>



<p>様々なデータがあると思いますが、一番良く使うのは箱ひげ図や散布図ではないでしょうか。それらをよりわかりやすくビジュアライズしていきたい方向けの基礎的なテクニックです！</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="962" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">ボックスプロット(箱ひげ図)とドットプロットを描く</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-2">baseのboxplotとbeeswarmライブラリを用いて作図する</a></li><li class="rtoc-item"><a href="#rtoc-3">ggplot2を用いてボックスプロットとドットプロットを作図する</a></li><li class="rtoc-item"><a href="#rtoc-4">ggbeeswarmを用いてggplot2のドットを散らばらせる</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-5">ggplot2でバイオリンプロットを描く</a></li><li class="rtoc-item"><a href="#rtoc-6">ggplot2を使って散布図を描く</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">散布図と近似直線を描く方法</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-8">複数データはfacet_gridとfacet_wrapを使う</a></li><li class="rtoc-item"><a href="#rtoc-9">geom_barで棒グラフを作図する</a></li><li class="rtoc-item"><a href="#rtoc-10">geom_errorbarで棒グラフと折れ線グラフにエラーバーをつける</a></li><li class="rtoc-item"><a href="#rtoc-11">geom_tileで相関行列のヒートマップをつくる</a></li><li class="rtoc-item"><a href="#rtoc-12">背景の一部(四角)に色をつけるgeom_rect</a></li><li class="rtoc-item"><a href="#rtoc-13">ROC曲線を描く</a></li></ol></div><h2 id="rtoc-1" >ボックスプロット(箱ひげ図)とドットプロットを描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/method_beeswarm_mod-1024x768.jpg" alt="" class="wp-image-863" width="512" height="384"/></figure>



<p>このグラフは<span class="marker">ドットプロット</span>と呼ばれます。箱ひげ図の上にドットプロットを重ねています。</p>



<p>箱ひげ図(box plot)とドットプロット(dot plot)は実際のデータがどのような分布になっているのかみるのに有用です。これで外れ値などもよくわかりますし、誤魔化している感じがない正直なプロットです。</p>



<p>base機能とbeeswarmパッケージを用いた方法とggplot2を使う方法があります。ggplot2を使う場合にはggbeeswarmというパッケージを使うとよりきれいになります。</p>



<h3 id="rtoc-2" >baseのboxplotとbeeswarmライブラリを用いて作図する</h3>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/box_beeswarm8-1024x1024.jpg" alt="" class="wp-image-738" width="512" height="512"/></figure>



<p>箱ひげ図は、baseと呼ばれるRに元々入っている機能を使ったものです。箱ひげ図はかんたんにかけますが、その後のドットプロットについてはbeeswarmというライブラリを使います。beeswarmは蜂群図とも呼ばれ、点を散らばらせることで視覚的に印象的にみせる効果があります。beeswarmライブラリで簡単に作図をすることができます。</p>



<p>x軸の並び替えもこちらに書いています。</p>



https://brain-storm.space/beeswarm_r/698/



<h3 id="rtoc-3" >ggplot2を用いてボックスプロットとドットプロットを作図する</h3>



<p>ggplot2を使うのに慣れた人向けの方法です。これは単純なドットプロットを描く方法で、いわゆるbeeswarm(蜂群図)ではありませんが、視覚的効果は十分にあります。</p>



https://brain-storm.space/rggplot2_boxplot_dotplot/620/



<h3 id="rtoc-4" >ggbeeswarmを用いてggplot2のドットを散らばらせる</h3>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/ggbeeswarm1-1024x1024.jpg" alt="" class="wp-image-874" width="512" height="512"/></figure>



<p>ggplot2でもbeeswarm(蜂群図)を作成することができます。これにはggplot2に加えて、ggbeeswarmというライブラリを使います。点の散らし方にもいくつかの方法があります。</p>



https://brain-storm.space/ggbeeswarm/820/



<h2 id="rtoc-5" >ggplot2でバイオリンプロットを描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_5-1024x1024.jpg" alt="" class="wp-image-881" width="512" height="512"/></figure>



<p>バイオリンプロットも複数のデータを比較する時にとても便利です。とてもキレイな図になります。この中では、バイオリンプロットにドットプロットや箱ひげ図の重ね方を説明しています。バイオリンプロットはggplot2のgeom_violinで描くことができます。</p>



https://brain-storm.space/violin-plot/871/



<h2 id="rtoc-6" >ggplot2を使って散布図を描く</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/scatterplot12-1024x1024.jpg" alt="" class="wp-image-772" width="512" height="512"/></figure>



<p>相関を数字で出すよりも実際に散布図を出したほうがより直感的にもわかりやすくなります。これも正直な印象を与えることができます。　ggplot2を用いて、geom_pointで散布図を、geom_smoothまたはstat_smoothで近似曲線を表示できます。</p>



<h3 id="rtoc-7" >散布図と近似直線を描く方法</h3>



https://brain-storm.space/rggplot_scatterplot/751/



<h2 id="rtoc-8" >複数データはfacet_gridとfacet_wrapを使う</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/facet_wrap7-1024x512.jpg" alt="" class="wp-image-935" width="512" height="256"/></figure>



<p>複数データを一度に表示したいとき、一つ一つ出していたのでは大変です。そんなときはfacet_gridやfacet_wrapを使うと一度にできて、見栄えのあるグラフができます。</p>



<p>またタイトルラベルなどの変え方にも少しテクニックが必要なので、その説明も加えています。</p>



https://brain-storm.space/r_facet/843/



<h2 id="rtoc-9" >geom_barで棒グラフを作図する</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/07/bargraph7-1024x819.jpg" alt="" class="wp-image-1036" width="512" height="410"/></figure>



<p>棒グラフは最も基本的なグラフの一つです。エクセルでも出来てしまうので、それほど困らないかもしれませんが、ggplot2でも簡単に出来てしまいます。次のリンクで紹介をしています。</p>



https://brain-storm.space/bargraph/1025/



<h2 id="rtoc-10" >geom_errorbarで棒グラフと折れ線グラフにエラーバーをつける</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar6-1024x614.jpg" alt="" class="wp-image-911" width="512" height="307"/></figure>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar10-1024x614.jpg" alt="" class="wp-image-915" width="512" height="307"/></figure>



<p>棒グラフや折れ線グラフは平均値の大小や推移などを可視化するのによく使われます。データ解析ではそこにエラーバーをつけたりしますが、そのやり方も知らなくては作図ができません。</p>



<p>さらにRでの<span class="marker">標準偏差や標準誤差の算出方法も説明しています</span>。計算で標準誤差などを出せば簡単に作図ができます。</p>



https://brain-storm.space/ggplot2_errorbar/895/



<h2 id="rtoc-11" >geom_tileで相関行列のヒートマップをつくる</h2>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/cormat7-1-1024x819.jpg" alt="" class="wp-image-994" width="512" height="410"/></figure>



<p>相関行列をつくったとき、それをテーブルにしても十分ですが、それを視覚的にわかりやすくするとより印象的な図になります。一目でデータが理解出来るのは、大きなメリットになります。</p>



<p>ggplot2以外のいくつかのパッケージでも描くことはできますが、ggplot2を使った方法を説明しています。それを紹介したのは次のリンクになります。</p>



https://brain-storm.space/corrheatmap/942/



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<p>ggplot2を使うときにデータを横長のデータから縦長のデータへ変換する必要があるときがあります。そんなときはpivot_longerを使うことで簡単に変換をすることができます。これは次の記事で詳細に説明をしています。</p>



https://brain-storm.space/tidyr_gather_pivot_longer/784/



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<p>今回紹介した作図法だけでも、論文のグラフの多くは作図ができると思います。今後もさらなる方法を広めて行きたいと思っています。</p>



<h2 id="rtoc-12" >背景の一部(四角)に色をつけるgeom_rect</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig6.jpeg" alt="" class="wp-image-1199" width="400" height="400"/></figure>



<p>背景に色をつけて、その部分を強調したり、領域を分けたいことがあります。そんな時はgeom_rectを使います。</p>



https://brain-storm.space/geom_rect/1191/



<h2 id="rtoc-13" >ROC曲線を描く</h2>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_final_8-1.jpeg" alt="ROC曲線" class="wp-image-1251" width="400" height="400"/><figcaption class="wp-element-caption">ROC curve</figcaption></figure>



<p>ROC曲線を書くのは思ったよりも簡単です。Rの初心者でも短時間で書くことができます。AUC(Area under the curve)の比較もあっという間です。</p>



https://brain-storm.space/roc-curve/1212/



<p>今後もさらに追加していく予定です。お役に立ちましたら幸いです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/r_graph/962/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【R初心者向け】ggplot2で棒グラフと折れ線グラフにエラーバー(error bar)を書く</title>
		<link>https://brain-storm.space/ggplot2_errorbar/895/</link>
					<comments>https://brain-storm.space/ggplot2_errorbar/895/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 12:20:55 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[bar graph]]></category>
		<category><![CDATA[error bar]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[エラーバー]]></category>
		<category><![CDATA[棒グラフ]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=895</guid>

					<description><![CDATA[棒グラフや折れ線グラフなどについている#8221;T#8221;が上下についているものがエラーバーです。エラーバーは標準誤差や標準偏差を示しています。 Rのggplot2を使えば簡単にできます。ステップバイステップで]]></description>
										<content:encoded><![CDATA[
<p>棒グラフや折れ線グラフなどについている&#8221;T&#8221;が上下についているものがエラーバーです。エラーバーは標準誤差や標準偏差を示しています。</p>



<p>Rの<span class="marker">ggplot2を使えば簡単にできます</span>。ステップバイステップで書いていきます。</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="895" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">データの準備する</a></li><li class="rtoc-item"><a href="#rtoc-2">データの平均、標準偏差、標準誤差を算出する</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3">dplyrのgroup_byとsummarise_allを使う</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-4">棒グラフでエラーバーを描く</a></li><li class="rtoc-item"><a href="#rtoc-5">折れ線グラフでエラーバーを描く</a></li><li class="rtoc-item"><a href="#rtoc-6">グループ化されたデータでのエラーバーを加える</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">グループ化された棒グラフにエラーバーを追加する</a></li><li class="rtoc-item"><a href="#rtoc-8">グループ化された折れ線グラフでのエラーバーを書く</a></li></ul></li></ol></div><h2 id="rtoc-1" >データの準備する</h2>



<p>tidyverseを利用します。自分のデータを使う場合には読み飛ばしてください。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
# 作業ディレクトリのセット
setwd(&quot;~/Rpractice/&quot;)

# tidyverseの起動
library(tidyverse)

# ランダムデータの生成
dat &lt;- list(
  X &lt;- rnorm(50, 30, 10),
  Y &lt;- rnorm(50, 50, 5),
  Z &lt;- rnorm(50, 40, 15)
)
df &lt;- data.frame(matrix(unlist(dat), nrow=50))
colnames(df) &lt;- c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;)

#データの変形(横から縦へ)
df.long &lt;- pivot_longer(df, cols = A:C, 
                        names_to = &quot;Categories&quot;, 
                        values_to = &quot;Values&quot;)
</pre></div>


<p>これでこのようなデータができました。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; head(df.long)
# A tibble: 6 x 2
  Categories Values
  &lt;chr&gt;       &lt;dbl&gt;
1 A            26.8
2 B            53.7
3 C            27.3
4 A            31.0
5 B            58.7
6 C            56.2
&gt; 
</pre></div>


<p>棒グラフと折れ線グラフにエラーバーを加えるには、平均値と標準誤差(または標準偏差)が必要です。pivot_longerで縦長データにしています。</p>



https://brain-storm.space/tidyr_gather_pivot_longer/784/



<h2 id="rtoc-2" >データの平均、標準偏差、標準誤差を算出する</h2>



<p>エラーバーのためには平均(mean)、標準偏差(sd)、標準誤差(se)を算出します。すでにこれらのデータがある場合にはここも読み飛ばしてください。</p>



<p>その算出方法も慣れれば簡単です！tidyverseに入っているdplyrを使っていきましょう。</p>



<h3 id="rtoc-3" >dplyrのgroup_byとsummarise_allを使う</h3>



<p>(summariseはアメリカ英語でsummarizeでもOKです)</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
a &lt;- group_by(df.long, Categories) %&gt;% 
  summarise_all(list(mean = ~mean(.), 
                     sd = ~sd(.), 
                     se = ~sd(.)/sqrt(length(.))))

</pre></div>


<p>これはもう少し簡素化できます。どちらを使っても大丈夫です。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
a &lt;- group_by(df.long, Categories) %&gt;% 
  summarise_all(list(mean = mean, 
                     sd = sd, 
                     se = ~sd/sqrt(length(.))))

</pre></div>


<p>ではaのデータをみてみます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; a
# A tibble: 3 x 4
  Categories  mean    sd    se
  &lt;chr&gt;      &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
1 A           30.1  9.93 1.40 
2 B           49.2  5.00 0.708
3 C           43.9 15.5  2.20 
</pre></div>


<p>このような分布になりました。データはランダムで生成しましたので、同じ手順をなぞってもこの数値は若干変化します。</p>



<h2 id="rtoc-4" >棒グラフでエラーバーを描く</h2>



<p>計算をしたデータを使って棒グラフをかきます。<span class="marker">エラーバーはgeom_errorbarで指定します</span>。まずはgeom_errorbarでyminとymaxのみを指定して、グラフをみてみましょう。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean, fill = Categories))+
  geom_bar(stat = &quot;identity&quot;) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se))

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar1-1024x614.jpg" alt="" class="wp-image-905" width="512" height="307"/></figure>



<p>横幅が広すぎますね。<span class="marker">これをwidthで調整します。</span>バーグラフ、エラーバーともに狭くしてみます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean, fill = Categories))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1)

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar2-1024x614.jpg" alt="" class="wp-image-906" width="512" height="307"/></figure>



<p>幅は出力する画像の大きさに合わせて適宜調整をするといいです。</p>



<h2 id="rtoc-5" >折れ線グラフでエラーバーを描く</h2>



<p>折れ線グラフも上と同じ要領です。折れ線グラフを描いて、geom_errorbarを付け足します。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(a, aes(x = Categories, y = mean)) +
  geom_line(group = 1) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar3-1024x614.jpg" alt="" class="wp-image-907" width="512" height="307"/></figure>



<h2 id="rtoc-6" >グループ化されたデータでのエラーバーを加える</h2>



<p>グループ化したデータを生成してみます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&lt;pre class=&quot;wp-block-syntaxhighlighter-code&quot;&gt;# IDを追加する
data &lt;- df.long %&gt;% 
  tibble::rownames_to_column(var = &quot;ID&quot;)

# IDを文字列から数値へ変換する
data$ID &lt;- as.numeric(data$ID)

# IDが75以下を1, 76以上を0と割り当てて、group列を作る
data &lt;- mutate(data, group = ifelse(ID &lt; 76, 1, 0))

# mean, SD, SEを算出
b &lt;- group_by(data, group, Categories) %&gt;% 
  summarise_at(vars(Values), list(mean = ~mean(.), 
                     sd = ~sd(.), 
                     se = ~sd(.)/sqrt(length(.))))

# group列の数値を文字列に変換する
b$group &lt;- as.character(b$group)

# bに含まれているデータを確認する
&gt; head(b)
# A tibble: 6 x 5
# Groups:   group &lt;img class=&quot;ranking-number&quot; src=&quot;https://brain-storm.space/wp-content/themes/jin/img/rank02.png&quot; /&gt;
  group Categories  mean    sd    se
  &lt;chr&gt; &lt;chr&gt;      &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
1 0     A           31.4 11.1  2.21 
2 0     B           51.0  4.31 0.862
3 0     C           33.9 13.5  2.70 
4 1     A           29.5 10.4  2.08 
5 1     B           49.5  4.02 0.804
6 1     C           36.5 15.8  3.16 
&gt; &lt;/pre&gt;
</pre></div>


<p>これでグループ化されました。このデータでエラーバーの入った棒グラフを描いてみましょう。</p>



<h3 id="rtoc-7" >グループ化された棒グラフにエラーバーを追加する</h3>



<p>position = &#8220;dodge&#8221;をするとこのような棒グラフができます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar4-1024x614.jpg" alt="" class="wp-image-909" width="512" height="307"/></figure>



<p>これにエラーバーを加えていきます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group))+
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;)+
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), 
                    position = &quot;dodge&quot;, width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar5-1024x614.jpg" alt="" class="wp-image-910" width="512" height="307"/></figure>



<p>真ん中に寄ってしまいました。この位置は<span class="marker">position = position_dodge()で調整できます</span>。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, fill = group)) +
  geom_bar(stat = &quot;identity&quot;, width = 0.6, position = &quot;dodge&quot;) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                position = position_dodge(0.6), width = .1)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar6-1024x614.jpg" alt="" class="wp-image-911" width="512" height="307"/></figure>



<p>これでいい棒グラフができました！</p>



<h3 id="rtoc-8" >グループ化された折れ線グラフでのエラーバーを書く</h3>



<p>折れ線グラフも同じようにできます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_line() +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar7-1024x614.jpg" alt="" class="wp-image-913" width="512" height="307"/></figure>



<p>エラーバーが前面に出ていて重なっているので見にくくなっています。まず<span class="marker">エラーバーを後ろに持って</span><span class="marker">い</span><span class="marker">きます。</span></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;) +
  geom_line() +
  geom_point(size = 3)
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar8-1024x614.jpg" alt="" class="wp-image-914" width="512" height="307"/></figure>



<p>エラーバーが重なりは<span class="marker">左右にずらす</span>ことで解消ができます。さきほどの<span class="marker">position_dodgeを使います</span>！</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(b, aes(x = Categories, y = mean, group = group, color = group)) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                width = .1, color = &quot;black&quot;, position = position_dodge(.2)) +
  geom_line(position = position_dodge(.2)) +
  geom_point(size = 3, position = position_dodge(.2))

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/06/errorbar10-1024x614.jpg" alt="" class="wp-image-915" width="512" height="307"/></figure>



<p>これで折れ線グラフのエラーバーを加えることができました。お役に立ちましたら幸いです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/ggplot2_errorbar/895/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Violin Plot in R &#8211; How to Draw It &#8211;</title>
		<link>https://brain-storm.space/violin-plot-en/1265/</link>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 10:33:25 +0000</pubDate>
				<category><![CDATA[Statistical Analysis]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Violinplot]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1265</guid>

					<description><![CDATA[There are several ways to visualize data, and one of them is the violin plot! This method is useful for compar]]></description>
										<content:encoded><![CDATA[
<p>There are several ways to visualize data, and one of them is the violin plot! This method is useful for comparing multiple sets of data, and it has an appealing appearance.</p>



<p>First, you&#8217;ll need to prepare your data. While you&#8217;re at it, you can also check the data distribution using a dot plot.</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1265" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">Data Generation and Distribution Checking</a></li><li class="rtoc-item"><a href="#rtoc-2">Draw a Simple Violin Plot</a></li><li class="rtoc-item"><a href="#rtoc-3">Add Color to Violin Plot</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-4">Add Color to the Borders</a></li><li class="rtoc-item"><a href="#rtoc-5">Fill the interior of Violin Plot</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-6">Add Mean or Median to the Violin Plot</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">Add Mean</a></li><li class="rtoc-item"><a href="#rtoc-8">Add Median</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-9">Change the Degree of Smoothing</a></li><li class="rtoc-item"><a href="#rtoc-10">Overlaying a Box Plot</a></li></ol></div><h2 id="rtoc-1" >Data Generation and Distribution Checking</h2>



<p>Now, let&#8217;s create some data. If you have your own data, feel free to use that instead.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
# Set working directory
setwd(&quot;~/Rpractice/&quot;)
# load tidyverse and ggbeeswarm
library(tidyverse)
library(ggbeeswarm)

# generate sample data
dat &lt;- list(
  X &lt;- rnorm(100, 5, 10),
  Y &lt;- rnorm(100, 20, 10),
  Z &lt;- rnorm(100, 15, 15)
)

# format the data into a more usable shape using pivot_longer
df &lt;- data.frame(matrix(unlist(dat), nrow=100))
colnames(df) &lt;- c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;)
df.long &lt;- pivot_longer(df, cols = A:C, names_to = &quot;Categories&quot;, values_to = &quot;Values&quot;)

# draw dotplot
ggplot(df.long, aes(x = Categories, y = Values))+
  geom_beeswarm(aes(color = Categories),
                size = 2,
                cex = 2,
                alpha = .8)+
  theme_classic()+
  theme(legend.position = &quot;none&quot;)

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/ggbeeswarm1-1024x1024.jpg" alt="" class="wp-image-874" width="512" height="512"/></figure>



<p>The dot plot displays the data distribution and can be used to confirm that the data is appropriate for creating a violin plot.</p>



<h2 id="rtoc-2" >Draw a Simple Violin Plot</h2>



<p>To draw a violin plot using ggplot2, you can utilize the geom_violin() function. To create a clean and simple plot, set the background color to white using the theme_classic() function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values))+
  geom_violin()+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_1-1024x1024.jpg" alt="" class="wp-image-876" width="512" height="512"/></figure>



<p>The ends of the violin plot may appear cut off. By overlaying a dot plot on top of the violin plot, you can address this issue. To do so, you can use either geom_dotplot() or geom_beeswarm(), which are both part of the ggplot2 package.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values))+
  geom_violin()+
  geom_beeswarm(aes(color = Categories),
                size = 2,
                cex = 2,
                alpha = .8)+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_2-1024x1024.jpg" alt="" class="wp-image-877" width="512" height="512"/></figure>



<p>You can see that the ends of this violin plot are cut off at the minimum and maximum values. If you don&#8217;t want to cut off the ends, you can use geom_violin(trim = FALSE) to specify this preference.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values))+
  geom_violin(trim = FALSE)+
  geom_beeswarm(aes(color = Categories),
                size = 2,
                cex = 2,
                alpha = .8)+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_3-1024x1024.jpg" alt="" class="wp-image-878" width="512" height="512"/></figure>



<p>The violin plot may stretch vertically up and down, even in areas where there are no data points.</p>



<h2 id="rtoc-3" >Add Color to Violin Plot</h2>



<h3 id="rtoc-4" >Add Color to the Borders</h3>



<p>To add color to the border of the violin plot, you can use aes(color = ) inside the geom_violin() function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, color = Categories))+
  geom_violin()+
  theme_classic()

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_4-1024x1024.jpg" alt="" class="wp-image-879" width="512" height="512"/></figure>



<h3 id="rtoc-5" >Fill the interior of Violin Plot</h3>



<p>If you want to fill the interior of the violin plot with color, you can use aes(fill =) inside the geom_violin() function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin()+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_5-1024x1024.jpg" alt="" class="wp-image-881" width="512" height="512"/></figure>



<p>There are several ways to change the color of the violin plot. One way is to use the scale_fill_brewer() function to specify the color scheme.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin()+
  scale_fill_brewer(palette = &quot;Set2&quot;)+
  theme_classic()

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_6-1024x1024.jpg" alt="" class="wp-image-882" width="512" height="512"/></figure>



<h2 id="rtoc-6" >Add Mean or Median to the Violin Plot</h2>



<p>To add the mean or median to the violin plot, you can use the stat_summary() function.</p>



<h3 id="rtoc-7" >Add Mean</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, color = Categories))+
  geom_violin()+
  stat_summary(fun = mean, geom = &quot;point&quot;, 
               shape = 16, size = 2, color = &quot;red&quot;)+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_7-1024x1024.jpg" alt="" class="wp-image-885" width="512" height="512"/></figure>



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<p>The shape parameter in stat_summary() is the same as pch in base R. Here&#8217;s a list of shapes that correspond to each numerical value:</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/pch_figure-5.png" alt="" class="wp-image-722" width="693" height="389"/></figure>



<div class="wp-block-jin-gb-block-border jin-sen"><div class="jin-sen-solid" style="border-width:3px;border-color:#f48789"></div></div>



<h3 id="rtoc-8" >Add Median</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, color = Categories))+
  geom_violin()+
  stat_summary(fun = median, geom = &quot;point&quot;, 
               shape = 3, size = 2, color = &quot;red&quot;)+
  theme_classic()

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_8-1024x1024.jpg" alt="" class="wp-image-886" width="512" height="512"/></figure>



<h2 id="rtoc-9" >Change the Degree of Smoothing</h2>



<p>To change the degree of smoothing in the violin plot, you can use the adjust parameter inside the geom_violin() function. The default value for adjust is 1.</p>



<p>To decrease the degree of smoothing, you can set adjust to a smaller value. For example, to set adjust to 0.2, you can use the following code:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin(adjust = .2)+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_9-1024x1024.jpg" alt="" class="wp-image-888" width="512" height="512"/></figure>



<p>Conversely, if you want to increase the degree of smoothing in the violin plot, you can set the adjust parameter to a larger value.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin(adjust = 2)+
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_10-1024x1024.jpg" alt="" class="wp-image-889" width="512" height="512"/></figure>



<p>If you increase the degree of smoothing too much, the violin plot can become overly smoothed and lose important details.</p>



<h2 id="rtoc-10" >Overlaying a Box Plot</h2>



<p>Overlaying a violin plot with a box plot is a common technique in data visualization, and it can be a powerful way to display data.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin()+
  geom_boxplot(width = .1, fill = &quot;white&quot;)+
  theme_classic()

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_boxplot1-1024x1024.jpg" alt="" class="wp-image-890" width="512" height="512"/></figure>



<p>To hide the outliers in the box plot when overlaying it with a violin plot, you can use the outlier.color parameter inside the geom_boxplot() function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values, fill = Categories))+
  geom_violin()+
  geom_boxplot(width = .1, fill = &quot;white&quot;, outlier.color = NA)+
  theme_classic()

</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_boxplot2-1024x1024.jpg" alt="" class="wp-image-891" width="512" height="512"/></figure>



<p>You can fill the box plot with black color and add a white circle at the median value.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot(df.long, aes(x = Categories, y = Values))+
  geom_violin()+
  geom_boxplot(width = .1, fill = &quot;black&quot;, outlier.color = NA) +
  stat_summary(fun = median, geom = &quot;point&quot;, fill = &quot;white&quot;, shape = 21, size = 3) +
  theme_classic()
</pre></div>


<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/gg_violin_boxplot3-1024x1024.jpg" alt="" class="wp-image-892" width="512" height="512"/></figure>



<p>With the information provided, I believe you can now create a violin plot. I hope this guidance proves helpful!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>【R初心者向け】自分でROC曲線(ROC curve)を書く</title>
		<link>https://brain-storm.space/roc-curve/1212/</link>
					<comments>https://brain-storm.space/roc-curve/1212/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Thu, 23 Mar 2023 10:11:56 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[pROC]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[ROC]]></category>
		<category><![CDATA[sentitivity]]></category>
		<category><![CDATA[specificity]]></category>
		<category><![CDATA[医療]]></category>
		<category><![CDATA[学会]]></category>
		<category><![CDATA[感度]]></category>
		<category><![CDATA[曲線]]></category>
		<category><![CDATA[特異度]]></category>
		<category><![CDATA[発表]]></category>
		<category><![CDATA[統計]]></category>
		<category><![CDATA[論文]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1212</guid>

					<description><![CDATA[ROC曲線の書き方を紹介します。RではROC曲線を書くのはとても簡単です。ROC曲線を描くためのライブラリはたくさんありますが、今回はよく使われていて使いやすいpROCライブラリでの書き方を紹介します。EZRなどでも書く]]></description>
										<content:encoded><![CDATA[
<p>ROC曲線の書き方を紹介します。RではROC曲線を書くのはとても簡単です。ROC曲線を描くためのライブラリはたくさんありますが、今回はよく使われていて使いやすいpROCライブラリでの書き方を紹介します。EZRなどでも書くことはできますが、自分で書ける方が色々と応用できます。</p>



<h3 id="rtoc-1" >サンプルデータを作る</h3>



<p>ここはサンプルデータを作るだけのところですので、不要な方は次の見出しに読み飛ばしてください。二つの検査、&#8221;assay1&#8243;と&#8221;assay2&#8243;でどの程度疾患の人を検出できるのかを検討してみます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
set.seed(3)
condition &lt;- rep(c(&quot;healthy&quot;, &quot;disease&quot;), each = 50)
assay1 &lt;- c(rnorm(40, mean = 1, sd = 2), 
            rnorm(10, mean = 3, sd = 1), 
            rnorm(40, mean = 5, sd = 2), 
            rnorm(10, mean = 7, sd = 1))
assay2 &lt;- c(rnorm(30, mean = 1, sd = 3), 
            rnorm(20, mean = 2, sd = 2), 
            rnorm(30, mean = 3, sd = 3), 
            rnorm(20, mean = 4, sd = 2))

df = data.frame(condition, assay1, assay2)
</pre></div>


<p>ちなみにこれらの分布はこのようなものになります。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
library(beeswarm)
beeswarm(data = df, assay1 ~ condition, 
         col = c(&quot;red&quot;,&quot;blue&quot;), pch=19)
beeswarm(data = df, assay2 ~ condition,
         col = c(&quot;red&quot;, &quot;blue&quot;), pch=19)
</pre></div>


<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/dotplot_assay1.jpeg" alt="" class="wp-image-1220" width="400" height="400"/><figcaption class="wp-element-caption">Assay1のdotplot</figcaption></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/dotplot_assay2.jpeg" alt="" class="wp-image-1221" width="400" height="400"/><figcaption class="wp-element-caption">Assay2のdotplot</figcaption></figure>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1212" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-1">サンプルデータを作る</a></li><li class="rtoc-item"><a href="#rtoc-2">pROCを使ってみる</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3">pROCパッケージのインストール</a></li><li class="rtoc-item"><a href="#rtoc-4">1つのROC曲線を描く</a></li><li class="rtoc-item"><a href="#rtoc-5">パーセント表示にする</a></li><li class="rtoc-item"><a href="#rtoc-6">感度の信頼区間を表示する</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-7">カットオフに最適な点を表示する</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-8">Youden Indexによる最適なカットオフを表示する</a></li><li class="rtoc-item"><a href="#rtoc-9">Top Leftによる最適なカットオフを表示する</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-10">必要な数値を取り出す</a></li><li class="rtoc-item"><a href="#rtoc-11">2つのROC曲線を重ねて比較する</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-12">2つのROC曲線を重ねる</a></li><li class="rtoc-item"><a href="#rtoc-13">2つの検査について比較する</a></li></ul></li></ol></div><h2 id="rtoc-2" >pROCを使ってみる</h2>



<h3 id="rtoc-3" >pROCパッケージのインストール</h3>



<p>pROCパッケージをインストールして、起動します。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
install.packages(&quot;pROC&quot;)
library(pROC)
</pre></div>


<h3 id="rtoc-4" >1つのROC曲線を描く</h3>



<p>早速いってみましょう。まずデータフレームは次のようになっています。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; head(df)
  condition     assay1     assay2
1   healthy -0.9238668  2.8520501
2   healthy  0.4149486 -0.2152325
3   healthy  1.5175764  4.1593113
4   healthy -1.3042638  2.8068527
5   healthy  1.3915657  4.0523835
6   healthy  1.0602479  2.8245020
</pre></div>


<p>ここからもいくつか方法はありますが、まずroc()を使って、その結果をオブジェクトに格納してみましょう。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
</pre></div>


<p>次のように&#8221;~&#8221;を使う書き方でも大丈夫です。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(df$condition ~ df$assay1, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
</pre></div>


<p>conditionの列は0, 1でもいけますが2値変数です。ciは信頼区間です。</p>



<p>plot()でROC曲線を描くことができます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_1.jpeg" alt="" class="wp-image-1224"/><figcaption class="wp-element-caption">Assay1</figcaption></figure>



<h3 id="rtoc-5" >パーセント表示にする</h3>



<p>好みにより軸をパーセント表示にすることができます。percent=TRUEを付け加えます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, percent=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
plot(roc1)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_plot2_percent.jpeg" alt="" class="wp-image-1225"/></figure>



<h3 id="rtoc-6" >感度の信頼区間を表示する</h3>



<p>感度の信頼区間を計算するには ci.se()を使います。colは色を指定します。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
plot(roc2)
rocCI &lt;- ci.se(roc2)
plot(rocCI, type=&quot;shape&quot;, col=&quot;lightblue&quot;)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_ci_3.jpeg" alt="" class="wp-image-1227"/></figure>



<h2 id="rtoc-7" >カットオフに最適な点を表示する</h2>



<p>ROC曲線から大事なことは、カットオフに最も適した点を調べることです。最適なカットオフは何か、というところも大きなテーマですが、ここでは２つの方法を紹介します。&#8221;Youden Index&#8221;と&#8221;top left&#8221;です。簡単に説明すれば、Youden Indexは&#8221;<span class="marker">感度+特異度-1</span>&#8221; で計算され、その数値が一番高いところを選びます。また、top leftは<span class="marker">ROC曲線の一番左上に近い点</span>を抽出します。</p>



<h3 id="rtoc-8" >Youden Indexによる最適なカットオフを表示する</h3>



<p>この時にはplotの中に追記をしていきます。<span class="marker2">print.thres = &#8220;best&#8221;, print.thres.bes.metod = &#8220;youden&#8221;</span>とすると最適点が表示されます。また、<span class="marker">legacy.axes=TRUEにするとx軸を1-Specificityになります。</span></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1, main = &quot;ROC Curve&quot;,      
     identity = TRUE,
     print.thres = &quot;best&quot;,
     print.thres.best.method = &quot;youden&quot;,
     legacy.axes = TRUE)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_youden_5.jpeg" alt="" class="wp-image-1231"/><figcaption class="wp-element-caption">Youden Index (J = 感度 + 特異度 &#8211; 1) による最適なカットオフ</figcaption></figure>



<p>この場合カットオフは3.912で感度が0.820、特異度は0.960です。</p>



<h3 id="rtoc-9" >Top Leftによる最適なカットオフを表示する</h3>



<p>top leftの場合は<span class="marker">print.thres.best.method=&#8221;closest.topleft&#8221;</span>にします。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
plot(roc1, main = &quot;ROC Curve&quot;,      
     identity = TRUE,
     print.thres = &quot;best&quot;,
     print.thres.best.method = &quot;closest.topleft&quot;
     legacy.axes = TRUE)

</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_topleft_4.jpeg" alt="" class="wp-image-1234"/><figcaption class="wp-element-caption">topleftによる最適なカットオフ</figcaption></figure>



<p>この場合のカットオフは3.365、感度0.860、特異度0.880になっています。括弧内は特異度、感度の順番になっていることに注意をしてください。</p>



<h2 id="rtoc-10" >必要な数値を取り出す</h2>



<p>AUC(area under the curve)の値や感度、特異度などの数値を発表や論文で示す必要があります。その時には次のように表示できます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; auc(roc1)
Area under the curve: 0.9536

# youden
&gt; coords(roc1, &quot;best&quot;, ret=c(&quot;threshold&quot;, &quot;sens&quot;, &quot;spec&quot;, &quot;ppv&quot;, &quot;npv&quot;))
          threshold sensitivity specificity       ppv       npv
threshold  3.912407        0.82        0.96 0.9534884 0.8421053

# topleft
&gt; coords(roc1, &quot;best&quot;, best.method=&quot;closest.topleft&quot;,　ret=c(&quot;threshold&quot;, &quot;sens&quot;, &quot;spec&quot;, &quot;ppv&quot;, &quot;npv&quot;))
          threshold sensitivity specificity      ppv       npv
threshold  3.364778        0.86        0.88 0.877551 0.8627451
</pre></div>


<h2 id="rtoc-11" >2つのROC曲線を重ねて比較する</h2>



<p>今回2つの検査を想定してサンプルデータを作りました。どちらの検査が優れているかみていきます。</p>



<h3 id="rtoc-12" >2つのROC曲線を重ねる</h3>



<p>２つのROC曲線を重ねる時には後から重ねる方をlines()にします。または単純にplot(&#8230;, add=TRUE)でも同じ結果になります。colで色を指定しています。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
# ２つの検査について、roc()を使ってその結果をオブジェクトに格納する
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

# linesを使う
obj1 &lt;- plot(roc1,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)

# add = TRUEにする
obj1 &lt;- plot(roc1,
             col=&quot;red&quot;)
obj2 &lt;- plot(roc2,
             col=&quot;blue&quot;,
             add=TRUE)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_two_assay_6.jpeg" alt="" class="wp-image-1239"/></figure>



<h3 id="rtoc-13" >2つの検査について比較する</h3>



<p>2つの検査について比較する時には<span class="marker">roc.test()を使います</span>。デフォルトではAUC(area under the curve)をDeLong法で比較しますが、method = &#8220;bootstrap&#8221;と指定すればブートストラップ法などにも変更できます。textで中央にp値を表示しています。また<span class="marker">タイトルはmain=で指定できます。</span></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

obj1 &lt;- plot(roc1,
             main=&quot;Comparison&quot;,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)
obj &lt;- roc.test(obj1, obj2)
text(.5, .5, labels=paste(&quot;p-value =&quot;, format.pval(obj$p.value, 3)), 
     adj=c(0, .5))
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_7.jpeg" alt="" class="wp-image-1242"/></figure>



<p>比較の結果を見るだけだったらroc.test()で結果が出てきます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
&gt; roc.test(roc1, roc2)

	DeLong's test for two correlated ROC curves

data:  roc1 and roc2
Z = 3.7621, p-value = 0.0001685
alternative hypothesis: true difference in AUC is not equal to 0
95 percent confidence interval:
 0.0969536 0.3078464
sample estimates:
AUC of roc1 AUC of roc2 
     0.9536      0.7512 
</pre></div>


<p>最後にlegendを入れてみます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
roc1 &lt;- roc(condition, assay1, data=df, ci=TRUE,
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))
roc2 &lt;- roc(condition, assay2, data=df, ci=TRUE, 
            levels=c(&quot;healthy&quot;, &quot;disease&quot;))

obj1 &lt;- plot(roc1,
             main=&quot;Comparison&quot;,
             col=&quot;red&quot;)
obj2 &lt;- lines(roc2,
              col=&quot;blue&quot;)

obj &lt;- roc.test(obj1, obj2)

# p values in the graph
text(.5, .5, labels=paste(&quot;p-value =&quot;, format.pval(obj$p.value, 3)), 
     adj=c(0, .5))

#legend
legend(&quot;bottomright&quot;, legend=c(&quot;Assay1&quot;, &quot;Assay2&quot;),
       col=c(&quot;red&quot;, &quot;blue&quot;), lty=1, lwd=2)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/roc_comparison_final_8-1.jpeg" alt="" class="wp-image-1251"/></figure>



<p>綺麗なROC曲線を書くことができました。<br>いかがでしたでしょうか。お役に立ちましたら幸いです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/roc-curve/1212/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【R簡単テクニック】背景に四角の領域(背景)をいれる</title>
		<link>https://brain-storm.space/geom_rect/1191/</link>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Mon, 06 Mar 2023 22:01:58 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[geom_rect]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1191</guid>

					<description><![CDATA[ggplotを使ったグラフの中に、四角の領域を入れる方法を紹介します。とても簡単です。ggplot2を使うためまずはライブラリのtidyverse(またはggplot2)を起動します。 資格の領域を作るにはgeom_re]]></description>
										<content:encoded><![CDATA[
<p>ggplotを使ったグラフの中に、四角の領域を入れる方法を紹介します。とても簡単です。ggplot2を使うためまずはライブラリのtidyverse(またはggplot2)を起動します。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
library(tidyverse)
</pre></div>


<p>資格の領域を作るにはgeom_rectを使います。その領域をxmin, xmax, ymin, ymaxで指定します。その領域の色はデフォルトで灰色(grey20)になっています。</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1191" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">geom_rectの使い方</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-2">まずは書いてみます</a></li><li class="rtoc-item"><a href="#rtoc-3">色を塗る</a></li><li class="rtoc-item"><a href="#rtoc-4">枠線の色を塗る</a></li><li class="rtoc-item"><a href="#rtoc-5">グラフ外まで領域が広がっている時</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-6">複数の領域を書きたい時</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-7">この時はデータフレームで領域を指定すると楽になります</a></li></ul></li><li class="rtoc-item"><a href="#rtoc-8">他のグラフの背景にする</a></li></ol></div><h2 id="rtoc-1" >geom_rectの使い方</h2>



<h3 id="rtoc-2" >まずは書いてみます</h3>



<p>四角の領域を書くにはgeom_rectを使います。x軸の最小値(xmin)と最大値(xmax)、y軸の最小値yminと最大値ymaxをしています。すると次のようなグラフが描けます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot() +
　geom_rect(aes(xmin=1, xmax=3, ymin=2, ymax=5))
</pre></div>


<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig1.jpeg" alt="" class="wp-image-1192" width="400" height="400"/></figure>



<h3 id="rtoc-3" >色を塗る</h3>



<p>色をつけていきます。中の色はfillで指定します。今はレジェンドが邪魔なので消しておきます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: Code example; notranslate">
ggplot() +
  geom_rect(aes(xmin=1, xmax=3, ymin=2, ymax=5, fill='red')) +
  theme(legend.position = &quot;none&quot;)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig2.jpeg" alt="" class="wp-image-1193"/></figure>



<h3 id="rtoc-4" >枠線の色を塗る</h3>



<p>次にその領域の枠の色も指定します。color=&#8217;色&#8217;で枠線の色が入ります。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: Code example; notranslate">
ggplot() +
geom_rect(aes(xmin=1, xmax=3, ymin=2, ymax=5, fill='red'), color='blue') +
  theme(legend.position = &quot;none&quot;)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig3.jpeg" alt="" class="wp-image-1194"/></figure>



<h3 id="rtoc-5" >グラフ外まで領域が広がっている時</h3>



<p>例えば、その図の外側までずっと続くような感じのグラフにしたい場合、Infを使うとできます。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
ggplot()+
  geom_rect(aes(xmin=0, xmax=Inf, ymin=0, ymax=Inf, fill='red'), color='red') +
  scale_x_continuous(limits = c(-2, 6)) + 
  scale_y_continuous(limits = c(-2, 6)) +
  theme(legend.position = &quot;none&quot;)
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig4.jpeg" alt="" class="wp-image-1196"/></figure>



<p>マイナス方向でずっと領域が続く時には-Infを使います。複数の領域を書く方法はまたあとで書きますが、-Infを使うと次のようになります。</p>



<p>透明度はalphaで1より小さく、そして小さい値ほど透明になります。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
df &lt;- data.frame(x1=c(-Inf, 0), x2=c(0, Inf), y1=c(-Inf, 0), y2=c(0, Inf), 
                group=c('a', 'b'))
ggplot() +
  geom_rect(data=df, aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2, fill=group), 
           alpha=0.3) +
  scale_x_continuous(limits = c(-6, 6)) + 
  scale_y_continuous(limits = c(-6, 6)) +
  theme_minimal()

</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig5.jpeg" alt="" class="wp-image-1197"/></figure>



<h2 id="rtoc-6" >複数の領域を書きたい時</h2>



<h3 id="rtoc-7" >この時はデータフレームで領域を指定すると楽になります</h3>



<p>複数の四角を作りたい時、データフレームにします。下の式ではx1が左辺、x2が右辺のx座標、y1が下辺、y2が上辺のy座標です。データフレームではさらにグループ分けもしています。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
df=data.frame(x1=c(1,2, 3,5), x2=c(5, 8, 5,Inf), 
              y1=c(1, 2, 2, 4), y2=c(2, 3, 6,Inf), 
             group=c('a', 'a','b','b'))
ggplot() +
geom_rect(data=df, aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2, fill=group), 
          color='black', alpha=0.3) +
scale_x_continuous(limits =c(0, 10)) +
scale_y_continuous(limits = c(0, 7))
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig6.jpeg" alt="" class="wp-image-1199"/></figure>



<p>scale_x_continuousとscale_y_continuousでx軸とy軸のどの数値まで入れるか指定しています。</p>



<h2 id="rtoc-8" >他のグラフの背景にする</h2>



<p>使い所としては他のグラフの背景にして目立たせるということでしょう。ggplot2は記述を＋で重ねて行くだけなので、とても簡単です。単純な直線のグラフの背景として書いてみます。geom_ablineが追加された斜めの線です。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: Code example; notranslate">
rect &lt;- data.frame(x1=c(-Inf, 0), x2=c(0, Inf), y1=c(-Inf, 0), y2=c(0, Inf), 
                group=c('a', 'b'))
ggplot()+
  geom_rect(data=rect, aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2, fill=group), 
            alpha=0.3) +
  geom_abline(intercept=0, slope = 1) +
  scale_x_continuous(limits = c(-6, 6)) + 
  scale_y_continuous(limits = c(-6, 6)) +
  theme_minimal()
</pre></div>


<figure class="wp-block-image size-full"><img decoding="async" width="400" height="400" src="https://brain-storm.space/wp-content/uploads/2023/03/geom_rect_fig7.jpeg" alt="" class="wp-image-1201"/></figure>



<p>いかがだったでしょうか。わかってしまえば簡単です。ぜひ試してみてください。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>【オーストリア移住経験】ビザD申請</title>
		<link>https://brain-storm.space/%e3%80%90%e3%82%aa%e3%83%bc%e3%82%b9%e3%83%88%e3%83%aa%e3%82%a2%e7%a7%bb%e4%bd%8f%e7%b5%8c%e9%a8%93%e3%80%91%e3%83%93%e3%82%b6d%e7%94%b3%e8%ab%8b/1136/</link>
					<comments>https://brain-storm.space/%e3%80%90%e3%82%aa%e3%83%bc%e3%82%b9%e3%83%88%e3%83%aa%e3%82%a2%e7%a7%bb%e4%bd%8f%e7%b5%8c%e9%a8%93%e3%80%91%e3%83%93%e3%82%b6d%e7%94%b3%e8%ab%8b/1136/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Wed, 03 Aug 2022 11:56:11 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1136</guid>

					<description><![CDATA[オーストリアに移住をすることになりました。約1ヶ月の出発までの期間で色々な手続きが必要でしたので、経験をふまえ、今後の参考になるようにまとめていこうと思います。 2021年10月頃の話です。手順はどんどん変わっていますの]]></description>
										<content:encoded><![CDATA[
<p>オーストリアに移住をすることになりました。約1ヶ月の出発までの期間で色々な手続きが必要でしたので、経験をふまえ、今後の参考になるようにまとめていこうと思います。</p>



<p>2021年10月頃の話です。<span class="marker">手順はどんどん変わっていますので、最新の情報は在京オーストリア大使館のホームページから手に入れてください。</span></p>



<p><a href="https://www.bmeia.gv.at/ja/oeb-tokio/">https://www.bmeia.gv.at/ja/oeb-tokio/</a></p>



<p>まずは自分がどのビザが必要なのかを確認しましょう。自分はビザDが必要でしたので、その経験を説明します。一発OKが出ることは少なく、大体が追加提出になったりするので、最初の訪問でしっかり揃えて行ったほうがいいでしょう。</p>



<p>コロナ前は大阪と名古屋にも申請できるところがありましたが、自分が行ったときにはどちらもコロナ禍で閉鎖をされていましたので、在京オーストリア大使館に行くしかありませんでした。再開状況については下のリンクを確認してください。</p>



<p><a href="https://visa.vfsglobal.com/jpn/ja/aut/news/for-austrian-visa-applicant">https://visa.vfsglobal.com/jpn/ja/aut/news/for-austrian-visa-applicant</a></p>



<p>在京オーストリア大使館は港区元麻布にあります。六本木からも徒歩圏内ですし、麻布十番駅からも比較的すぐ近くです。地方在住の方は近場のホテルで宿泊すると便利です。</p>



<figure class="wp-block-image size-medium"><img decoding="async" width="225" height="300" src="https://brain-storm.space/wp-content/uploads/2021/11/IMG_6588-1-225x300.jpg" alt="" class="wp-image-1148"/><figcaption>オーストリア大使館の入り口</figcaption></figure>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1136" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">ビザなしでも6ヶ月未満は滞在できる - ただし研究や雇用などにはビザが必要</a></li><li class="rtoc-item"><a href="#rtoc-2">訪問日の予約取得</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3"><strong>申請用紙</strong></a></li><li class="rtoc-item"><a href="#rtoc-4">パスポートとそのコピー</a></li><li class="rtoc-item"><a href="#rtoc-5">ICAO規格による最近の写真(パスポートサイズ)</a></li><li class="rtoc-item"><a href="#rtoc-6">旅行保険証書</a></li><li class="rtoc-item"><a href="#rtoc-7"><strong>雇用証明書</strong>　(現在の雇用関係を証明する在職証明書、雇用者、仕事、期間、収入)、在学証明書</a></li><li class="rtoc-item"><a href="#rtoc-8"><strong>フライト予約確定書</strong></a></li><li class="rtoc-item"><a href="#rtoc-9"><strong>宿泊の予約証明、ホテルの予約</strong></a></li><li class="rtoc-item"><a href="#rtoc-10"><strong>充分な資金の証明、通帳</strong>（6ヶ月分の残高証明）</a></li><li class="rtoc-item"><a href="#rtoc-11"><strong>オーストリアの次に訪問される訪問国のビザ</strong></a></li><li class="rtoc-item"><a href="#rtoc-12"><strong>返信用封筒</strong></a></li></ul></li></ol></div><h2 id="rtoc-1" >ビザなしでも6ヶ月未満は滞在できる &#8211; ただし研究や雇用などにはビザが必要</h2>



<p>まずは自分にビザが必要なのか、そうではないのか、あるいは帯同する家族がいる場合にはどうなのか、など調べ始めはわからないことばかりです。</p>



<p>オーストリアは6ヶ月までビザなしでも入国できますが、雇用されるなどの場合にはビザを入国前に取得しておく必要があります。またビザなし入国の場合3-6ヶ月の場合に、他のシェンゲン協定の国々は「あらゆる180日の期間内で最大90日間」の滞在が認められています。つまり、オーストリアに3ヶ月以上滞在して、他のシェンゲン協定の別の国に入った場合には不法滞在になる可能性があります。トランジットの場合にも特に注意が必要です。</p>



<blockquote class="wp-block-quote"><p><strong>オーストリアに3ヶ月以上</strong>（180日未満）滞在する日本国旅券所持者は直行便でオーストリアに出入国しない場合、非シェンゲン加盟国経由で出入国するか、シェンゲンビザを取得しなければなりません。</p><cite>https://www.bmeia.gv.at/ja/oeb-tokio/reisen-nach-oesterreich/visa/</cite></blockquote>



<p>自分の場合は雇用をされるのでビザが必要、帯同する家族は不要でした。ただし、ビザは6ヶ月未満ですので、6ヶ月以上滞在の場合は滞在許可申請が別途必要になります。ややこしいところですが、ビザDを取得して、入国後に滞在許可申請を行う、あるいはビザDと滞在許可申請を在京オーストリア大使館で行うの二通りがあります。</p>



<p>滞在許可はすでに住むところが決まっている必要があったり、書類が別途必要でオーストリア入国前には間に合いそうになかったので、入国後に行いました。これについてはまた別の記事で説明をしようと思います。</p>



<h2 id="rtoc-2" >訪問日の予約取得</h2>



<p>ホームページを確認したところ、予約はメールでのアポイント取得になります。<strong><span class="marker">現在、２－３週間先まで予約がほぼ一杯という状況</span></strong>とのことですので、余裕を持った申込みが必要です。</p>



<p>この記載に気づかず悠長にかまえていたところにこの一文を見つけて相当焦りました。ビザが認められるのも1−2週間位は見ておいたほうがよさそうです。パスポートを預けてしまうので、出国ギリギリになるとかなりヒヤヒヤします。</p>



<p>メールにわからないことの質問も丁寧に答えてもらえます(多分)がまずはホームページを読み込むのが大切です。</p>



<p>必要なものは以下の通りです(2021年11月現在)。</p>



<h3 id="rtoc-3" ><strong>申請用紙</strong></h3>



<p>申請用紙はドイツ語と英語です。意味がわかってもやっぱりわかりにくいです。</p>



<p>上から書いていって最初に迷うのがPlace of Birthです。Japanと書こうとしたらその下にCountry of Birthと国名を書く欄があるので、ここは都道府県名が無難でしょう。何故か日本のパスポートはガラパゴス的に本籍地の記載があり、出生地の記載がありませんが、出生地の記載があれば便利なのに、とはいつも思います。</p>



<p><em>Number of entries requested</em>も調べるまでよくわかりませんでした。もし帰国や他国へ行って再入国をする可能性があるのであればMultiple entriesにしておくのが安全かと思います。</p>



<p><em>&nbsp;Duration of the intended stay or transit</em>には滞在予定期間を書きます。</p>



<p><em>Intended date of departure</em>は出国予定日を記入します。滞在許可で長期に滞在する予定の場合にも出国予定日を一応記入します。例えば3年滞在する予定であれば、3年後の日にちを書いて大丈夫です。</p>



<p><em>Surname and first name of the inviting person(s) in the Member State(s). If not applicable, name of hotel(s) or temporary accommodation(s) in the Member State(s).</em>は滞在先について記入します。到着後の一時しのぎにホテルへ滞在する場合にも、ホテルの名前を記入します。</p>



<p><em>Cost of travelling and living during the applicant&#8217;s stay is covered</em>は滞在中の資金が自分のお金か他からの資金か, などを記載します。</p>



<p>最後に<em>Place and date</em>と<em>Signature</em>があります。サインする時に場所を書くことは日本でそれほど馴染みがないですが、オーストリアでは一般的でした。Tokyo, 申請日(date-month-year)で記載すれば問題ありません。日にちから書くのが一般的です。</p>



<h3 id="rtoc-4" >パスポートとそのコピー</h3>



<p>パスポートとそのコピーを持参します。身分事項ページのコピーが必要です。パスポートは預けてしまいますので、それとは別に身分事項ページをスキャンしておくか、コピーを手元に置いておくといいです。2週間位は手元にない状態になります。滞在先受入機関とのやり取りなど、色々な場面でパスポートの番号が必要だったり、パスポートのコピーを求められたりすることがあります。某社の海外引っ越しを申し込んだときにもパスポートのコピーが必要でしたが、あらかじめスキャンをしておいたので大丈夫でした。</p>



<p>有効残存期間は必ず確認をしましょう。外国籍の方は日本の在留カードも必要です。</p>



<h3 id="rtoc-5" >ICAO規格による最近の写真(パスポートサイズ)</h3>



<p>写真はパスポート申請の場所の写真屋さんで撮影をしました。パスポートで使えるものであれば問題はないと思います。一か八かで行くより、確実に大丈夫なものを持っていったほうがいいです。</p>



<p><a href="https://www.mofa.go.jp/mofaj/toko/passport/ic_photo.html">https://www.mofa.go.jp/mofaj/toko/passport/ic_photo.html</a></p>



<h3 id="rtoc-6" >旅行保険証書</h3>



<p>十分な保証のある保険証書が必要です。旅行保険とありますが、急な疾病をカバーするものがです。自分の場合はケアコンセプト社のケアオーストリアを申し込んでいましたので、その保険証書を持っていきました。現地で公的な健康保険に入る場合には、その入るまでの期間の旅行保険に入れば大丈夫ですが、いつから公的な健康保険に入ることができるのかを受け入れ先または会社から一筆書いてもらうように同じ時間に申請に来てた人は指摘をされていました。</p>



<p>また当時はCOVID-19についてもカバーしている証明が必要です、と指摘をされました。病気の保険だから普通にカバーされるでしょ、とは思いましたが、明記してある必要があるとのことで、ホームページを探したのと、直接問い合わせを行い、追加で郵送の提出をしました。</p>



<h3 id="rtoc-7" ><strong>雇用証明書</strong>　(現在の雇用関係を証明する在職証明書、雇用者、仕事、期間、収入)、在学証明書</h3>



<p>在職中の方は雇用証明書や在学証明書が必要ですので、在籍機関に出してもらいましょう。退職して渡航をする場合には不要ですが、観光以外では受け入れ先からの証明(アクセプタンスレターや招待状など)になります。</p>



<h3 id="rtoc-8" ><strong>フライト予約確定書</strong></h3>



<p>ビザがおりたら予約ではなく、<span class="marker">すでにフライトを予約してある状態でビザ申請に行く必要があります。</span>なので、渡航日を決めてから逆算して(できればなるべく早く)ビザ申請に行く日を決めましょう。ホームページには出発の３週間前までに、と書いてありますが、予約を申し込んでから最短で２−３週間かかることもあります。自分の場合は出発の２週間前になってしまいました。出発日が刻一刻と近づく中でパスポートがなかなか戻ってこないので、ヒヤヒヤしました。</p>



<h3 id="rtoc-9" ><strong>宿泊の予約証明、ホテルの予約</strong></h3>



<p>すでに賃貸などで決まっている場合にはその契約書などを持っていくのがいいです。また、一時しのぎのホテルなどでも特に問題はなさそうです。自分の場合は５日分の宿泊予約をしたホテルのconfirmationをプリントアウトして持っていきましたが、問題ありませんでした。</p>



<h3 id="rtoc-10" ><strong>充分な資金の証明、通帳</strong>（6ヶ月分の残高証明）</h3>



<p>6ヶ月分の入出金明細をプリントアウトまたはコピーをして持っていきます。６ヶ月分のプリントアウトをしたつもりが１ヶ月分だけ抜けていたりしても指摘をされました。また<span class="marker">新しく作った口座で６ヶ月分の履歴がないものよりは６ヶ月入出金</span><span class="marker">履歴</span><span class="marker">がある口座のほうが良い</span>とのことでした。さらに前日の入出金歴があるほうが良いようです。２つの口座をコピーしていったのですが、一つは上記のように一ヶ月抜けていて、もう一つは新しく作った口座だったので、6ヶ月分の歴がなかったのと、名前の入った部分をコピーし忘れたので、どちらも却下になり、結局は新しくコピーした前者を郵送で提出しました。</p>



<h3 id="rtoc-11" ><strong>オーストリアの次に訪問される訪問国のビザ</strong></h3>



<p>これについては該当しなかったので、よくわかりません。</p>



<h3 id="rtoc-12" ><strong>返信用封筒</strong></h3>



<p>返信用封筒はレターパックプラスという赤いものになります。配達が速達並の速さですし、追跡もできますので、渡すときに追跡番号をはがして自分の手元にとっておけばいつ発送したかがわかります。ちなみに大使館にも置いてあるので、そこで買うこともできます。</p>



<p>返信用封筒でビザの貼られたパスポートが入って返ってきます。</p>



<p>再提出書類があった場合にはレターパックライトというもので提出をします。余談ですが、レターパックプラスは対面渡し、レターパックライトはポスト投函での配達になります。</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/11/IMG_6588-768x1024.jpg" alt="" class="wp-image-1142" width="384" height="512"/><figcaption>オーストリア大使館の玄関です。インターホンを押して、厳重な扉の鍵を開けてもらいました。</figcaption></figure>



<p>やることは複雑でわからないことも多いですが、時間的に余裕のあるうちに下調べをしっかりして行った方がいいと思います。ここを参考にしている方はちょうど渡航に向けて準備している方だと思います。渡航に向けた一つ目の山場だと思いますので、頑張ってください。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/%e3%80%90%e3%82%aa%e3%83%bc%e3%82%b9%e3%83%88%e3%83%aa%e3%82%a2%e7%a7%bb%e4%bd%8f%e7%b5%8c%e9%a8%93%e3%80%91%e3%83%93%e3%82%b6d%e7%94%b3%e8%ab%8b/1136/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>論文投稿tips【まとめ】</title>
		<link>https://brain-storm.space/papers_matome/1074/</link>
					<comments>https://brain-storm.space/papers_matome/1074/#respond</comments>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Mon, 02 Aug 2021 01:00:11 +0000</pubDate>
				<category><![CDATA[論文作成・統計]]></category>
		<category><![CDATA[paper]]></category>
		<category><![CDATA[science]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=1074</guid>

					<description><![CDATA[論文投稿をはじめて行う方は右も左もわからない状態です。実際研究成果がようやく出たと思ってからより、論文を作り上げてから投稿するまでのほうが大変だと感じることもあるかもしれません。 論文投稿についてのtipsをそのテーマご]]></description>
										<content:encoded><![CDATA[
<p>論文投稿をはじめて行う方は右も左もわからない状態です。実際研究成果がようやく出たと思ってからより、論文を作り上げてから投稿するまでのほうが大変だと感じることもあるかもしれません。</p>



<p>論文投稿についてのtipsをそのテーマごとにわけて記載をしてみました。</p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="1074" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">どの雑誌を選ぶか</a></li><li class="rtoc-item"><a href="#rtoc-2">英文校正の前に</a></li><li class="rtoc-item"><a href="#rtoc-3">カバーレターでdesk rejection率を下げる！</a></li><li class="rtoc-item"><a href="#rtoc-4">いよいよ投稿する投稿をしてから返事が来るまで</a></li><li class="rtoc-item"><a href="#rtoc-5">ジャーナルから返事が来たら</a></li><li class="rtoc-item"><a href="#rtoc-6">リバイスの方法</a></li><li class="rtoc-item"><a href="#rtoc-7">プレスリリース-論文に通ったあとに</a></li></ol></div><h2 id="rtoc-1" >どの雑誌を選ぶか</h2>



<p>雑誌選びについてとても慎重に考える必要があります。難しいジャーナルからチャレンジしていくのか、比較的通りそうなところをはじめから選んでいくのか、その可能性、労力、時間や通ったときのインパクトについてなど様々な要素から検討をしていく必要があります。</p>



https://brain-storm.space/select_journal/1083/



<h2 id="rtoc-2" >英文校正の前に</h2>



<p>論文は指導者のみではなく、他の共著者にも読んでもらうことが必要です。しっかり内容を読むかどうかはその共著者にもよるかもしれませんが、重要な指摘をもらえたり、間違いに気づいてもらえることもあります。当然ですが、投稿するための承諾なども必要です。</p>



<p>また研究者の同僚に英語のネイティブスピーカーがいればその人に英文をチェックしてもらうこともできますが、そのような環境の人もそれほど多くはないと思います。そのためそのような環境ではない人は論文の英語をしっかりチェックしてもらえる英文校正に出すことも必要です。</p>



https://brain-storm.space/paper1-3/333/



<h2 id="rtoc-3" >カバーレターでdesk rejection率を下げる！</h2>



<p>　比較的よく見るのが多いのが、カバーレターをほぼ定型文で書いているケースです。これではせっかく頑張って書いた論文の中身すら読んでもらえないことがあります。少なくともeditorial regectになりにくいカバーレターを目指しましょう。</p>



https://brain-storm.space/cover-letter/382/



<h2 id="rtoc-4" >いよいよ投稿する投稿をしてから返事が来るまで</h2>



<p>投稿したあとに現在どのような進行状況かを投稿サイトから知ることができます。しかしあっという間にそのステータスが変わったり、あるいは全然変わらなかったり。進行状況はわかりますが、その表示は雑誌によっても異なっており、ヤキモキすることも少なくありません。投稿してからの流れを解説したのが、次の記事です。</p>



https://brain-storm.space/paper1/233/



<h2 id="rtoc-5" >ジャーナルから返事が来たら</h2>



<p>投稿した雑誌からいつかは返事がきます。待ちに待った返事を開いてどうだったでしょうか。喜びや安堵の気持ちを抱くか、落胆や絶望感を味わうか、大きく感情が揺さぶられる瞬間です。しかし、次に何をすべきか、気持ちを切り替えて行くしかありません。せっかく頑張って書いた論文です。よっぽど論文に問題がある場合を除き、お蔵入りにさせず、強い信念で論文を通しましょう。</p>



https://brain-storm.space/paper1-2/280/



<h2 id="rtoc-6" >リバイスの方法</h2>



<p>major revisionやminor revisionになった時、その改訂の仕方にはそれなりの作法があります。せっかく改訂すればアクセプトにするという段階ですから、これを無駄にしてしまうことはできません。うまくいかなければリジェクトになる可能性もありますので、手を抜かずに慎重に進めましょう。</p>



https://brain-storm.space/paper-revision/408/



<h2 id="rtoc-7" >プレスリリース-論文に通ったあとに</h2>



<p>論文が通ったらプレスリリースをすることがあります。別にしなくても構いませんが、社会的にインパクトのありそうな研究だと考えているならば、プレスリリースをすることによって自分たちの研究を多くの人に知ってもらえるチャンスです。プレスリリースは論文がin pressの段階で行うのが効果的です。そのメリットと注意すべき点を記載しました。</p>



https://brain-storm.space/pressrelease/504/



<div class="wp-block-jin-gb-block-blank-space blank-space" style="height:30px"></div>



<p>論文が通るまでには大変な苦労があります。特にはじめての頃はよくわからないことがたくさんあります。</p>



<p>この記事がお役に立ちましたら幸いです。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://brain-storm.space/papers_matome/1074/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【論文紹介】卓球とパーキンソン病 &#8211; その効果への期待</title>
		<link>https://brain-storm.space/tabletennis/331/</link>
		
		<dc:creator><![CDATA[brainblog]]></dc:creator>
		<pubDate>Sun, 01 Aug 2021 01:19:51 +0000</pubDate>
				<category><![CDATA[脳機能の探求]]></category>
		<category><![CDATA[パーキンソン病]]></category>
		<category><![CDATA[卓球]]></category>
		<guid isPermaLink="false">https://brain-storm.space/?p=331</guid>

					<description><![CDATA[今回は日本でも割と人気のスポーツ、卓球について紹介をします。東京オリンピックでも盛り上がりましたね！オリンピック選手レベルになると、超人的なスピードでボールを打ち返しています。普通の人であのレベルはできるはずはありません]]></description>
										<content:encoded><![CDATA[
<p>今回は日本でも割と人気のスポーツ、卓球について紹介をします。東京オリンピックでも盛り上がりましたね！オリンピック選手レベルになると、超人的なスピードでボールを打ち返しています。普通の人であのレベルはできるはずはありませんが、卓球を普段していない人にとっても楽しみやすいスポーツです。</p>



<p>普段の診察でもパーキンソン病の患者さんに薬とともに運動をすすめています。<span class="marker">運動は治療の一つでもあります</span>。卓球は体力とともに素早い反応が必要です。来るボールに対して素早くラケットを出す、回転を見極めるなどの一瞬の判断力など、とても頭を使うスポーツとしても知られています。</p>



https://brain-storm.space/parkinson/229/



<p><br><br>卓球の効果は海外でも注目をされていますが、最近日本からもその効果を裏付ける発表がされています。</p>



<p><a href="https://www.sciencedirect.com/science/article/pii/S2590112520300542">https://www.sciencedirect.com/science/article/pii/S2590112520300542</a></p>



<div id="rtoc-mokuji-wrapper" class="rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default" data-id="331" data-theme="jin-child">
			<div id="rtoc-mokuji-title" class=" rtoc_left">
			<button class="rtoc_open_close rtoc_open"></button>
			<span>Contents</span>
			</div><ol class="rtoc-mokuji decimal_ol level-1"><li class="rtoc-item"><a href="#rtoc-1">パーキンソン病と卓球について</a></li><li class="rtoc-item"><a href="#rtoc-2">パーキンソン病患者のための卓球世界選手権が開催</a><ul class="rtoc-mokuji mokuji_ul level-2"><li class="rtoc-item"><a href="#rtoc-3">開催の経緯 - 卓球による症状の改善効果への期待</a></li><li class="rtoc-item"><a href="#rtoc-4">卓球を始めて症状が改善</a></li></ul></li></ol></div><h2 id="rtoc-1" >パーキンソン病と卓球について</h2>



<figure class="wp-block-image size-small_size"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/wan-san-yip-ITFi-ljkKU-unsplash-640x360.jpg" alt="table tennis" class="wp-image-530"/></figure>



<p>福岡大学から論文です。</p>



<p>12名トライアルに参加して9名の追跡ができています。週1回で、準備運動を入れた6時間の運動プログラムをやっています。</p>



<p>運動症状のスコアというのは、日常生活においてどのくらい不自由があるか、というアンケート形式のものと、診察で一つ一つの症状を評価するものがあります。</p>



<p>その<span class="marker">アンケート形式のスコアと身体診察による評価、そのどちらもで3ヶ月後、6ヶ月後に症状が改善をしていました</span>。特にパーキンソン病のお薬を新たに内服するわけでもないとのことです。</p>



<p>研究への参加者の数が少ないので、この論文の信頼性としてはやや劣ってしまいます。しかし、とても期待が持てる結果です。</p>



<h2 id="rtoc-2" >パーキンソン病患者のための卓球世界選手権が開催</h2>



<figure class="wp-block-image size-small_size"><img decoding="async" src="https://brain-storm.space/wp-content/uploads/2021/05/table-tennis-1208377_1280-640x360.jpg" alt="" class="wp-image-532"/></figure>



<p>最近ではパーキンソン病のある卓球選手による世界大会が開かれています。</p>



<p>2020年に開かれるはずだった第2回の世界大会が新型コロナウイルスの関係で、2021年9月にドイツのベルリンで行われる予定になっています。</p>



<p>今年の世界大会のホーページです。<br><a rel="noreferrer noopener" href="https://ittffoundation.org/programmes/tt4health/2021-ittf-parkinsons-world-table-tennis-championships" target="_blank">https://ittffoundation.org/programmes/tt4health/2021-ittf-parkinsons-world-table-tennis-championships</a></p>



<p>第1回はニューヨークで2019年に開催をされていました。</p>



<p>このリンク先の記事は入賞者の順位が掲載をされていますが、日本からの参加者も入賞していますね。おめでとうございます！！<br><a rel="noreferrer noopener" href="https://www.butterfly.co.jp/takurepo/tournament/detail/013395.html" target="_blank">https://www.butterfly.co.jp/takurepo/tournament/detail/013395.html</a></p>



<h3 id="rtoc-3" >開催の経緯 &#8211; 卓球による症状の改善効果への期待</h3>



<p>この世界大会の理念にはミュージシャンであり、パーキンソン病患者でもあったネナド・バッハさんが国際卓球連盟に提唱したことによって実現したとのことです。</p>



<p><br>詳しくは次のリンクの記事に書いてあります。<br><a rel="noreferrer noopener" href="https://www.butterfly.co.jp/takurepo/other/detail/006835.html" target="_blank">https://www.butterfly.co.jp/takurepo/other/detail/006835.html</a></p>



<blockquote class="wp-block-quote"><p>Nenad Bach氏はクロアチアのザグレブ出身。ニューヨークに住み、ミュージシャンとして活動していた。しかし、2010年にパーキンソン病にかかったことで、その音楽生活は暗転した。指先の動きに障害があらわれ、ギターは弾けなくなっていった。また、まっすぐ立つことも困難になってしまった。加えて、声を出すことすら難しくなってしまった。</p><cite>https://www.butterfly.co.jp/takurepo/other/detail/006835.html</cite></blockquote>



<p>ネナド・バッハさんは<span class="marker">2010年にパーキンソン病を患ってしまいました</span>。仕事してのギターも、そしてまっすぐ立ったり声を出すことすらも難しくなったとのことです。</p>



<h3 id="rtoc-4" >卓球を始めて症状が改善</h3>



<p>しかしネナド・バッハさんは2016年に<span class="marker">卓球を始めたことによって、再びギターを弾けるようになり、またまっすぐ立ったり声を出すこともできるようになりました</span>。</p>



<blockquote class="wp-block-quote"><p>2016年、Nenad Bach氏は卓球を始めた。子どもの頃に遊びでやっていた卓球を、再びやってみる気になったのだ。すると、歓迎すべき変化があらわれた。卓球をするようになってから、症状が改善する気配を感じたのだ。そこで、卓球をする頻度を増やしていったところ、症状は明らかに改善し、なんとギターが弾けるまでに回復。まっすぐ立てるようにもなった。声も出せるようになった。</p><cite>https://www.butterfly.co.jp/takurepo/other/detail/006835.html</cite></blockquote>



<p>2018年には国際卓球連盟の関係者に弾き語りをしたというのですから驚きです。2010年にパーキンソン病を発症したとのことであれば、すでに8年を経過しています。</p>



<p>卓球というスポーツは経験者と初心者の力の差があまりに大きな競技です。世界大会を見ると、小さいボールで人間業とは思えないような攻防を繰り広げています。</p>



<p>ネナド・バッハさんは子どもの頃に遊びでやっていた程度の卓球ということですから、ほぼ初心者に近い経験だと考えられます。</p>



<p>つまり、経験者が卓球を続けるということではなく、初心者でも運動の改善が期待できる、ということだと思います。</p>



<p>今の新型コロナウイルスの状況もあり、なかなか難しいかもしれませんが、これからの卓球の効果としての科学的なエビデンスが期待されます。</p>



<p>ぜひ運動は楽しんで行いましょう。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
