小米盒子4 拆解圖解_我希望當我開始學習R時會得到的盒子圖解指南

小米盒子4 拆解圖解

Customizing a graph to transform it into a beautiful figure in R isn’t alchemy. Nonetheless, it took me a lot of time (and frustration) to figure out how to make these plots informative and publication-quality. Rather than hoarding this information like a dragon presiding over its treasure, I want to share the code I use to plot data, explaining what each piece of it does.

自定義圖形以將其轉換為R中的漂亮圖形并不是煉金術。 盡管如此,我還是花了很多時間(和沮喪)來弄清楚如何使這些情節具有信息性和出版質量。 我要分享的是我用來繪制數據的代碼,而不是像巨龍一樣掌控著它的寶藏,而是解釋了每個信息的作用。

First thing’s first, let’s load our packages and generate a dummy dataset, with one independent variable and one continuous dependent variable. Before the code snippet, I’ll discuss the functions and arguments we will use. We also set an order for our categorical variables beforehand.

首先,讓我們加載包并生成一個虛擬數據集,其中包含一個自變量和一個連續因變量。 在代碼片段之前,我將討論我們將使用的函數和參數。 我們還預先為分類變量設置了順序。

虛擬數據集:函數和參數 (Dummy Dataset: Functions and arguments)

  • runif generates 100 numbers between 0 and 1

    runif生成100個介于0和1之間的數字

  • sample randomly selects the number 1 or 2, 100 times

    樣本隨機選擇數字1或2,進行100次

  • factor sets a preferred order for our grouping variables

    因子為分組變量設置了首選順序

### Load packages
install.packages('ggplot2')
install.packages('RColorBrewer')
install.packages('ggpubr')
library(ggplot2)
library(RColorBrewer)
library(ggpubr)#Create dummy dataset
ndf <- data.frame(
value = rep(runif(100)),
factor1 = as.char(rep(sample(1:2, replace = TRUE, 100))
)
ndf$factor1 = factor(ndf$factor1, levels = c('1', '2'))

箱形圖:函數和參數 (Box Plot: Functions and Arguments)

  • ggplot allows us to specify the independent and dependent variables, as well as the dataset to use for the graph

    ggplot允許我們指定自變量和因變量,以及用于圖的數據集

  • stat_boxplot lets us specify the type of whiskers to add onto the plot

    stat_boxplot讓我們指定要添加到繪圖中的晶須類型

  • geom_boxplot specifies the independent and dependent variables for the boxes in the plot

    geom_boxplot為圖中的框指定自變量和因變量

The first basic attempt isn’t very informative or visually appealing. We focus first on just plotting the first independent variable, factor1. I also don’t like the default grey theme within ggplot.

最初的基本嘗試不是很有啟發性或視覺吸引力。 我們首先專注于繪制第一個自變量factor1。 我也不喜歡ggplot中的默認灰色主題。

plot_data <- ggplot(ndf, aes(y = value, x = factor1)) +
stat_boxplot( aes(y = value, x = factor1 ),
geom='errorbar', width=0.5) +
geom_boxplot(aes(y = value, x = factor1))
Image for post
Generated by the author in R
由作者在R中生成

帶點的箱形圖:函數和參數 (Box Plot with Dots: Functions and Arguments)

  • theme_bw() sets a black-and-white theme for the plot, getting rid of the pesky grey background

    theme_bw()為情節設置了黑白主題,擺脫了討厭的灰色背景

  • geom_dotplot: binaxis specifies which variable will be displayed with the dots. The other arguments specify the appearance of the dots, while binwidth specifies how many dots we want in the same row on our plot. If you want to make the dots see-through, use the alpha argument which lets you specify the opacity of the dots from 0 to 1.

    geom_dotplot: binaxis指定將與點一起顯示的變量。 其他參數指定點的外觀,而binwidth指定在繪圖的同一行中需要多少個點。 如果要使點透明,請使用alpha參數,該參數可以指定點的不透明度從0到1。

Now our plot is more informative but it still needs improvement. We want to modify some of the colors, axes and labels.

現在我們的情節提供了更多信息,但仍需要改進。 我們要修改一些顏色,軸和標簽。

plot_data <- ggplot(ndf, aes(y = value, x = factor1)) +
stat_boxplot( aes(y = value, x = factor1 ),
geom='errorbar', width = 0.5) +
geom_boxplot(aes(y = value, x = factor1)) +
theme_bw() +
geom_dotplot(binaxis='y',
stackdir = "center",
binwidth = 1/20,
dotsize = 1,
aes(fill = factor1))
Image for post

出汗的小事情 (Sweating the Little Things)

  • scale_fill_manual lets us set specific colors for specific values of our independent variables

    scale_fill_manual讓我們為自變量的特定值設置特定的顏色

  • xlab and ylab allow us to label the x and y axis respectively. If you put the escape character following the newline symbol into the title (\n) it continues the rest of the label on the next line!

    xlab和ylab允許我們分別標記x和y軸。 如果將換行符后面的轉義字符放在標題(\ n)中,它將在下一行繼續其余標簽!

  • ggtitle names your plot

    ggtitle為您的情節命名

  • theme is a very customizable part of the script. It let’s us customize just about anything we want with its arguments. Since I don’t like the default grids placed in ggplots, I attribute element_blank to a few panel arguments to get rid of the border around the plot. I make the axis colored black rather than grey. I also specify how much blank space I want around the graph with plot_margin. Since this plot is simple, we get rid of the legend for this example. With the various axis_text arguments I set the size, font face, color and positioning of axis text and labels.

    主題是腳本中非常可定制的部分。 它使我們可以自定義幾乎所有我們想要的參數。 由于我不喜歡放置在ggplots中的默認網格,因此我將element_blank賦予一些面板參數以擺脫繪圖周圍的邊界。 我將軸設為黑色而不是灰色。 我還使用plot_margin指定想要在圖形周圍多少空白。 由于該圖很簡單,因此在此示例中,我們擺脫了圖例。 通過各種axis_text參數,我設置了軸文本和標簽的大小,字體,顏色和位置。

  • scale_y_continuous sets the y axis increases from 0 to 1 in 0.2 intervals. By expanding the limit of the plot beyond 1, it gives the title more breathing room. If I needed to use a y-axis with discrete variable names, I could use a different argument — scale_y_discrete.

    scale_y_continuous設置y軸以0.2的間隔從0增加到1。 通過將圖的限制擴展到超過1,可以為標題提供更多的喘息空間。 如果我需要使用帶有離散變量名稱的y軸,則可以使用其他參數-scale_y_discrete。

  • scale_x_discrete lets me relabel the two independent variables. This lets you quickly rename codified data. I’ve relabeled the independent variables as Danny DeVito and Nicolas Cage. Let’s posit that we are looking at how well Nic Cage and Danny DeVito performed at the box office using scores scaled between 0 and 1.

    scale_x_discrete讓我重新標記兩個自變量。 這使您可以快速重命名編碼的數據。 我將自變量重新標記為Danny DeVito和Nicolas Cage。 假設我們正在研究Nic Cage和Danny DeVito在0和1之間的得分在票房上的表現。

  • stat_compare_means lets you do statistical tests. This one’s here for you to explore! Just type stat_compare_means( and press tab to explore the different options available to you. Otherwise you can type ?stat_compare_means to get the help manual for this function!

    stat_compare_means使您可以進行統計檢驗。 這個在這里供您探索! 只需鍵入stat_compare_means(并按Tab鍵即可探索可用的其他選項。否則,您可以鍵入?stat_compare_means以獲得此功能的幫助手冊!

If you’re wondering about the hjust and vjust within different elements of the code, it simply allows us to change position of text elements. I added some flare by changing the boxplot line coloring as well as the fill of our dots. If you’re building a busy plot, it’s also important to check for accessibility. You can find colorblind friendly palette with this tool: https://colorbrewer2.org/.

如果您想知道代碼中不同元素之間的平衡,它只是允許我們更改文本元素的位置。 我通過更改箱形圖線的顏色以及點的填充來增加了耀斑。 如果您要建立繁忙的地塊,檢查可訪問性也很重要。 您可以使用此工具找到對色盲友好的調色板: https : //colorbrewer2.org/ 。

For convenience, I’ve bolded any changes in the code for the plot to make it easier to follow.

為了方便起見,我將圖中代碼的所有更改加粗了,以使其易于理解。

plot_data <- ggplot(ndf, 
aes(y = value, x = factor1, color = factor1))+
scale_color_manual(values =
c('1' = 'blue',
'2' = 'firebrick4')) +
stat_boxplot( aes(y = value, x = factor1 ),
geom='errorbar', width = 0.5) +
geom_boxplot(aes(y = value, x = factor1), shape = 2)+
theme_bw() +
geom_dotplot(binaxis='y',
stackdir = "center",
binwidth = 1/20,
dotsize = 1,
aes(fill = factor1)) +
scale_fill_manual(values = c('1' = '#0571b0', '2' = '#ca0020')) +
xlab("Independent\nVariable") + ylab("Dependent\nVariable") +
ggtitle("Box-Dot Plot") +
theme( panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
panel.border = element_blank(),
plot.margin=unit(c(0.5,0.5, 0.5,0.5),"cm"),
legend.position="none",
axis.title.x= element_text(size=14, color = 'black', vjust = 0.5),
axis.title.y= element_text(size=14, color = 'black', vjust = 0.5),
axis.text.x = element_text(size=12, color = 'black'),
axis.text.y = element_text(size=14, color = 'black'),
plot.title = element_text(hjust = 0.5, size=16, face = 'bold', vjust = 0.5)) +
scale_y_continuous(expand = c(0,0), breaks = seq(0,1,0.2),
limits = c(0,1.1)) +
scale_x_discrete(labels = c('Nicholas Cage', 'Danny DeVito'))
stat_compare_means(method = 't.test', hide.ns = FALSE, size = 4, vjust = 2)
Image for post

In a very short span of time, we’ve gone from a simple boxplot to a more visually appealing, accessible plot that gives us more information about the individual datapoints. You can save the code and modify it as you wish whenever you need to plot data. This makes the customization process so much easier! No more (okay maybe a lot less) computer defenestrations!

在很短的時間內,我們已經從簡單的箱形圖變成了更具視覺吸引力的可訪問圖,它為我們提供了有關各個數據點的更多信息。 您可以在需要繪制數據時保存并根據需要修改代碼。 這使定制過程變得非常容易! 沒有更多(好的,也許更少)計算機故障!

If you’re looking to download the code, find it here: https://github.com/simon-sp/R_ggplot_basic_dotplot. I’ve left plenty of comments within the code to help you out in case you get stuck! Remember that placing a question mark before a function brings up an instruction guide for you in RStudio!

如果您要下載代碼,請在這里找到它: https : //github.com/simon-sp/R_ggplot_basic_dotplot 。 我在代碼中留下了很多注釋,以幫助您避免被卡住! 請記住,在功能之前加一個問號會在RStudio中為您提供指導指南!

翻譯自: https://towardsdatascience.com/the-box-plot-guide-i-wish-i-had-when-i-started-learning-r-d1e9705a6a37

小米盒子4 拆解圖解

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388259.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388259.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388259.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

組態王仿真隨機數

1、新建IO設備&#xff0c;選擇PLC---亞控---仿真PLC&#xff0c;一直“下一步”。 2、在“數據詞典”中新建變量“Tag1”&#xff0c;雙擊Tag1&#xff0c;變量類型選&#xff1a;I/O實數&#xff1b;初始值設為&#xff1a;0.6&#xff1b;最小值設為&#xff1a;0.5&#xf…

藍牙一段一段_不用擔心,它在那里存在了一段時間

藍牙一段一段You’re sitting in a classroom. You look around and see your friends writing something down. It seems they are taking the exam, and they know all the answers (even Johnny who, how to say it… wasn’t the brilliant one). You realize that your ex…

Linux基礎命令---ifup、ifdown

ifupifup指令用來啟動網絡接口設備&#xff0c;設備必須是定義在“/etc/sysconfig/network-scripts/ifcfg-ethX”或者“/etc/sysconfig/network”的文件。這些腳本通常使用一個參數&#xff1a;配置的名稱(例如eth0)。在引導序列中&#xff0c;使用“boot”的第二個參數調用它們…

OllyDBG 入門之四--破解常用斷點設

OllyDBG 入門之四--破解常用斷點&#xff08;轉&#xff09; 軟件漢化2010-07-08 16:25:23 閱讀76評論0 字號&#xff1a;大中小 訂閱 bpx hmemcpy 破解萬能斷點&#xff0c;攔截內存拷貝動作 bpx Lockmytask 當你用其它斷點都無效時可以試一下&#xff0c;這個斷點攔截…

POJ1204 Word Puzzles

傳送門 這題果然是AC自動機的大好題&#xff01; 題目的大意是&#xff0c;給定一個l*c的大網格&#xff0c;每個格子里有一個字符&#xff0c;每個格子可以向八個方向形成字符串&#xff0c;問給定的字符串在哪里能被匹配以及在網格中出現的方向&#xff08;A代表北&#xff0…

普通話測試系統_普通話

普通話測試系統Traduzido/adaptado do original por Vincius Barqueiro a partir do texto original “Writing Alt Text for Data Visualization”, escrito por Amy Cesal e publicado no blog Nightingale.Traduzido / adaptado由 VinciusBarqueiro 提供原始 文本“為數據可…

Mac OS 被XCode搞到無法正常開機怎么辦?

Mac OS 被XCode搞到無法正常開機怎么辦&#xff1f; 第一天拿到這臺air的時候&#xff0c;迫不及待地把從別處搜集來的XCode 3.2.5iOS SDK 4.1的dmg安裝了上來&#xff0c;結果系統直接崩潰&#xff0c;再開機就不能正常開機&#xff0c;總是碰到kernel panic。這不坑爹嗎…… …

美國隊長3:內戰_隱藏的寶石:尋找美國最好的秘密線索

美國隊長3:內戰There are plenty of reasons why one would want to find solitude in the wilderness, from the therapeutic effects of being immersed in nature, to not wanting to contribute to trail degradation and soil erosion on busier trails.人們有很多理由想要…

Java入門第三季——Java中的集合框架(中):MapHashMap

1 package com.imooc.collection;2 3 import java.util.HashSet;4 import java.util.Set;5 6 /**7 * 學生類8 * author Administrator9 * 10 */ 11 public class Student { 12 13 public String id; 14 15 public String name; 16 17 public Set<…

【譯】 WebSocket 協議第八章——錯誤處理(Error Handling)

概述 本文為 WebSocket 協議的第八章&#xff0c;本文翻譯的主要內容為 WebSocket 錯誤處理相關內容。 錯誤處理&#xff08;協議正文&#xff09; 8.1 處理 UTF-8 數據錯誤 當終端按照 UTF-8 的格式來解析一個字節流&#xff0c;但是發現這個字節流不是 UTF-8 編碼&#xff0c…

升級xcode5.1 iOS 6.0后以前的橫屏項目 變為了豎屏

升級xcode5.1 iOS 6.0后以前的橫屏項目 變為了豎屏&#xff0c;以下為解決辦法&#xff1a; 在AppDelegate 的初始化方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中 將 [window addSubview: viewCon…

動漫數據推薦系統

Simple, TfidfVectorizer and CountVectorizer recommendation system for beginner.簡單的TfidfVectorizer和CountVectorizer推薦系統&#xff0c;適用于初學者。 目標 (The Goal) Recommendation system is widely use in many industries to suggest items to customers. F…

Wait Event SQL*Net more data to client

oracle 官方給的說法是 C.3.152 SQL*Net more data to client The server process is sending more data/messages to the client. The previous operation to the client was also a send. Wait Time: The actual time it took for the send to complete 意味著server process…

1.3求根之牛頓迭代法

目錄 目錄前言&#xff08;一&#xff09;牛頓迭代法的分析1.定義2.條件3.思想4.誤差&#xff08;二&#xff09;代碼實現1.算法流程圖2.源代碼&#xff08;三&#xff09;案例演示1.求解&#xff1a;\(f(x)x^3-x-10\)2.求解&#xff1a;\(f(x)x^2-1150\)3.求解&#xff1a;\(f…

libzbar.a armv7

楊航最近在學IOS&#xfeff;&#xfeff; http://download.csdn.net/download/lzwxyz/5546365 我現在用的是這個&#xff1a;http://www.federicocappelli.net/2012/10/05/zbar-library-for-iphone-5-armv7s/ 點它的HERE開始下載 下載的libzbar.a庫&#xff0c;如何查看 …

Alex Hanna博士:Google道德AI小組研究員

Alex Hanna博士是社會學家和研究科學家&#xff0c;致力于Google的機器學習公平性和道德AI。 (Dr. Alex Hanna is a sociologist and research scientist working on machine learning fairness and ethical AI at Google.) Before that, she was an Assistant Professor at th…

三位對我影響最深的老師

我感覺&#xff0c;教過我的老師們&#xff0c;不論他們技術的好壞對我都是有些許影響的。但是讓人印象最深的好像只有寥寥幾位。 第一位就是小學六年級下冊教過我的語文老師。他是臨時從一個貧困小學調任過來的&#xff0c;不怎么管班級&#xff0c;班里同學都在背地里說他不會…

安全開發 | 如何讓Django框架中的CSRF_Token的值每次請求都不一樣

前言 用過Django 進行開發的同學都知道&#xff0c;Django框架天然支持對CSRF攻擊的防護&#xff0c;因為其內置了一個名為CsrfViewMiddleware的中間件&#xff0c;其基于Cookie方式的防護原理&#xff0c;相比基于session的方式&#xff0c;更適合目前前后端分離的業務場景&am…

UNITY3D 腦袋頂血頂名

&#xfeff;&#xfeff;楊航最近在學Unity3D&#xfeff;&#xfeff; using UnityEngine; using System.Collections; public class NPC : MonoBehaviour { //主攝像機對象 public Camera camera; //NPC名稱 private string name "我是doud…

一個項目的整個測試流程

最近一直在進行接口自動化的測試工作&#xff0c;同時對于一個項目的整個測試流程進行了梳理&#xff0c;希望能對你有用~~~ 需求分析&#xff1a; 整體流程圖&#xff1a; 需求提取 -> 需求分析 -> 需求評審 -> 更新后的測試需求跟蹤xmind 分析流程&#xff1a; 1. 需…