ggplot2_labels

[Beginner] Graph for Communication - Label

Evan Jung 1/3/2019

1. Introduction

In EDA(Exploratory Data Analysis), many ways to build plots as tools for exploration. Most of you made each plot for some reason and purpose for clients. To let clients understand your data and graph, you need to know the way to communicate your thoughts and understandings to others.

We will review R for Data Science written by Garrett Grolemund & Hadley Wichham.

This simple article aims to R users who knows how to draw graph using tidyverse package. If you are newbie for R, then click above the link and read chapter 3 carefully.

We are on chater 28, though.

2. Label

The easiest place to start when turning an explorator graphic into an expository graphic is with good labels. You add labes with labs

(1) labs() function


What is titie? Well, in general, title is big picture of graph, summarizing the main finding. Part of facts, e.g. “A scatterplot of displ and hwy” is not the title because it has no any finding from Analyst.

(2) Subtitle & Caption

If you want to add more text, giving more information to clients, then you may think of subtitle & caption.


Look!

  • Subtitle adds additional detail in a smaller font beneath the title
  • caption adds text at the bottom right of the plot, often used to describe the source of the data

(3) x and y title replacement

Look graph 1 & 2. The titles of x and y are a bit strange to read it. Yes, clients can’t understand those abbreviation, so you want to spread it to full name. On the other hand, when you code with R, you want to select variable typing letters. Then, you might be introuble to code.

labs function makes both of group easy to do the job.


(4) Formula on X and Y

This is option. If you working with math, physics, etc. You want to put formula to x-axis and y-axis. Below the way.


It looks difficult. but You can do it with R Documentation. Type on code chunk ?plotmath like below

Let me introduce some quotes

Syntax Meaning
x + y x plus y
x - y x minus y
sqrt(x) square root of x


1. 사이트 맵이란?


사이트맵 사이트에 있는 페이지, 동영상 및 기타 파일과 각 관계에 관한 정보를 제공하는 파일입니다. 사이트맵을 등록하는 이유는 매우 간단합니다. 

내가 작성하는 블로그 또는 우리 회사의 웹사이트가 많은 사람들에게 

검색되어지기 위해서.

구글은 다음과 같이 정의합니다. 


"Google과 같은 검색엔진은 이 파일을 읽고 사이트를 더 지능적으로 크롤링하게 됩니다. 사이트맵은 크롤러에게 내가 사이트에서 중요하다고 생각하는 파일을 알리고 이러한 파일에 관한 중요한 정보를 제공합니다."


2. 사이트 맵 등록 방법은?

먼저 XML 생성기 싸이트에 방문합니다. 


(1) 싸이트 URL에 블로그 또는 회사 싸이트를 입력합니다. 

(2) Optional Sitemap Types과 Last Modification, Frequency에서 사이트 환경에 맞게 선택하여 주세요. 

(3) Create Sitemap을 클릭하면 3-5분 (제 티스토리 싸이트 기준) 소요되면 Broken Links와 XML sitemap에서 Download를 진행합니다. 

(4) 티스토리 사이트맵을 관리-서식관리에서 작성 후 아래와 같이 등록합니다. 



(5) 사이트맵이 등록된 페이지를 확인한 후 아래와 같이 xml 파일 주소를 복사(Copy) 합니다. 


3. 구글에서 내 웹사이트가 검색되어질 수 있도록 웹사이트 등록하기

(1) 구글 검색창에서 구글 서치콘솔을 검색하셔도 되고, 아니면 직접 해당페이지에 들어갈 수 있도록 구글사이트맵 테스트 도구를 클릭하셔도 됩니다. 그러면 아래와 같이 나올 것입니다. (참고로 전, 예전에 이미 등록해 둔 웹사이트가 있어서 그래프가 보여지는 것 뿐입니다.)



(2) 오른쪽 빨간색 버튼 (속성 추가 또는 ADD A PROPERTY)을 클릭하고 아래와 같이 웹싸이트를 입력합니다. 


(3) 웹싸이트 소유권 확인을 위한 절차입니다. 티스토리는 HTML 편집이 쉽기 때문에 HTML 태그를 활용하겠습니다. 


(4) 스킨편집을 클릭합니다. 


(5) 스킨편집에서 html 편집을 클릭합니다.  


(6) HTML에서 HTML 메타태그를 입력한 뒤 적용합니다.   


(7) 구글 서치 콘솔에서 확인을 누르면 아래와 같이 소유자 확인이 완료된 것입니다. 

4. 웹사이트 등록 후, 사이트맵 테스트 하기

(1) 이제 마지막으로 사이트맵 테스트를 진행해야 합니다. 새로운 Search Console 사용를 클릭합니다.   



(2) 다운받은 sitemap.xml을 블로그에 올린 뒤 파일로 첨부합니다. 그리고, 해당 페이지에서 아래와 같이 링크를 복사합니다. 



(3) 구글 서치콘솔에서 아래와 같이 새 사이트맵에 링크 주소를 복사한 후 제출합니다. 


(4) 아래와 같이 사이트맵 처리 완료가 되면 이제 끝입니다. 


이제 모두 끝입니다. 글을 올린 뒤, 최소한 한달에 한번정도는 사이트맵을 정기적으로 제출해야 검색이 잘 됩니다. 

모든 건, 늘 그렇듯이 꾸준해야 합니다. 

2018년 12월 31일 오후 11시~~~ Happy New Year




Edit

Docker installation on GCP

 

We are going to learn the way to set up and install docker on google compute engine.

All source codes and explanations came from How To Install and Use Docker on Ubuntu 16.06 on DigitalOcean


Step 1. Create a new Google Compute Engine (GCE) instance

  1. Go to your Google Cloud Platform console

  2. Create a new Google Compute Engine, with Debian 8 or Linux distort of your choice.

    • Give it a name

    • Choose a zone

    • Choose a machine type

    • Allow HTTP traffic

    • Click “Create”

  3. SSH into your new Google Compute Engine

Step 2. Install Docker on your new Google Compute Engine Machine

  1. Login as Super user

    • sudo -s

  2. First, in order to ensure the downloads are valid, add the GPG key for the official Docker repository to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. Add the Docker repository to APT sources:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  1. Next, update the package database with the Docker packages from the newly added repo:

sudo apt-get update

docker-ce:
Installed: (none)
Candidate: 5:18.09.0~3-0~ubuntu-xenial
Version table:
5:18.09.0~3-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
18.06.1~ce~3-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
18.06.0~ce~3-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
18.03.1~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
18.03.0~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.12.1~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.12.0~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.09.1~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.09.0~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.06.2~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.06.1~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.06.0~ce-0~ubuntu 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.03.3~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.03.2~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.03.1~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.03.0~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

  1. Finally, install Docker:

sudo apt-get install -y docker-ce
  1. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

sudo systemctl status docker

● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-12-27 15:50:28 UTC; 39s ago
Docs: https://docs.docker.com
Main PID: 14035 (dockerd)
CGroup: /system.slice/docker.service
└─14035 /usr/bin/dockerd -H unix://
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.226811162Z” level=warning msg=”Your kernel does not support swap memory limit”
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.227267680Z” level=warning msg=”Your kernel does not support cgroup rt period”
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.227457038Z” level=warning msg=”Your kernel does not support cgroup rt runtime”
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.229318131Z” level=info msg=”Loading containers: start.”
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.712759962Z” level=info msg=”Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon opti
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.796363894Z” level=info msg=”Loading containers: done.”
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.840844599Z” level=info msg=”Docker daemon” commit=4d60db4 graphdriver(s)=overlay2 version=18.09.0
Dec 27 15:50:27 database-server dockerd[14035]: time=”2018-12-27T15:50:27.841562244Z” level=info msg=”Daemon has completed initialization”
Dec 27 15:50:28 database-server systemd1: Started Docker Application Container Engine.
Dec 27 15:50:28 database-server dockerd[14035]: time=”2018-12-27T15:50:28.050783220Z” level=info msg=”API listen on /var/run/docker.sock”

Step 3. Executing the Docker Command Without Sudo (Optional)

  1. If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:

sudo groupadd docker
sudo usermod -aG docker ${USER}
  1. To apply the new group membership, you can log out of the server and back in, or you can type the following:

sudo passwd root
su - ${USER}
  1. You will be prompted to enter your user’s password to continue. Afterwards, you can confirm that your user is now added to the docker group by typing:

id -nG

Step 4. Working with Docker Images

docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.

  2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
    (amd64)

  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.

  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

docker run -it ubuntu bash

output

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
32802c0cfa4d: Pull complete
da1315cffa03: Pull complete
fa83472a3562: Pull complete
f85999a86bef: Pull complete
Digest: sha256:6d0e0c26489e33f5a6f0020edface2727db9489744ecc9b4f50c7fa671f23c49
Status: Downloaded newer image for ubuntu:latest
root@ffc2620c415b:/# exit
exit

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

docker images

output

REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 93fd78260bd1 5 weeks ago 86.2MB
hello-world latest 4ab4c602aa5e 3 months ago 1.84kB

Step 5. Running a Docker Container

Containers can be much more useful than that, and they can be interactive. After all, they are similar to virtual machines, only more resource-friendly.
As an example, let’s run a container using the latest image of Ubuntu. The combination of the -i and -t switches gives you interactive shell access into the container:

docker run -it ubuntu

output

root@f39fe297ef16:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [135 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1367 B]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [300 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
Get:9 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [6931 B]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [900 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [618 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [10.7 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [3655 B]
Fetched 15.3 MB in 3s (5453 kB/s)
Reading package lists... Done

Then install any application in it. Let’s install Node.js:

apt-get install -y nodejs

This installs Node.js in the container from the official Ubuntu repository. When the installation finishes, verify that Node.js is installed:

node -v

Output
v8.10.0

Step 6. Managing Docker Containers

After using Docker for a while, you’ll have many active (running) and inactive containers on your computer. To view the active ones, use:

docker ps

You will see output similar to the following:

output

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

To view all containers — active and inactive — run docker ps with the -a switch:

docker ps -a

output

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f39fe297ef16 ubuntu "/bin/bash" 9 hours ago Exited (0) 8 hours ago thirsty_turing
c5451bf09731 ubuntu "/bin/bash" 9 hours ago Exited (0) 9 hours ago nostalgic_archimedes
ffc2620c415b ubuntu "bash" 9 hours ago Exited (0) 9 hours ago unruffled_wright

To view the latest container you created, pass it the -l switch:

docker ps -l

output

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f39fe297ef16 ubuntu "/bin/bash" 9 hours ago Exited (0) 8 hours ago thirsty_turing

To start a stopped container, use docker start, followed by the container ID or the container’s name. Let’s start the Ubuntu-based container with the ID of :

docker start f39fe297ef16

To stop a running container, use docker stop, followed by the container ID or name. This time, we’ll use the name that Docker assigned the container, which is thirsty_turing.

docker stop thirsty_turing

Once you’ve decided you no longer need a container anymore, remove it with the docker rm command, again using either the container ID or the name. Use the docker ps -a command to find the container ID or name for the container associated with the hello-world image and remove it.

docker rm thirsty_turing

Step 7. Committing Changes in a Container to a Docker Image

This section shows you how to save the state of a container as a new Docker image.

docker commit -m "What did you do to the image" -a "Author Name" container-id repository/new_image_name

The -m switch is for the commit message that helps you and others know what changes you made, while -a is used to specify the author. The container ID is the one you noted earlier in the tutorial when you started the interactive Docker session. Unless you created additional repositories on Docker Hub, the repository is usually your Docker Hub username.

For example, for the user j2hoon85, with the container ID of a2cd48b54e5c, the command would be:

docker commit -m "added node.js" -a "j2hoon85" a2cd48b54e5c j2hoon85/ubuntu-nodejs
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
j2hoon85/ubuntu-nodejs latest b318da5e1778 9 seconds ago 170MB
ubuntu latest 93fd78260bd1 5 weeks ago 86.2MB
hello-world latest 4ab4c602aa5e 3 months ago 1.84kB

In the above example, ubuntu-nodejs is the new image, which was derived from the existing ubuntu image from Docker Hub. The size difference reflects the changes that were made. In this example, the change was that Node.js was installed. Next time you need to run a container using Ubuntu with Node.js pre-installed, you can just use the new image.

Step 8. Pushing Docker Images to a Docker Repository

To push an image to Docker Hub or any other Docker registry, you must have an account there.
This section shows you how to push a Docker image to Docker Hub. To learn how to create your own private Docker registry, check out How To Set Up a Private Docker Registry on Ubuntu 14.04.

docker login -u j2hoon85

You’ll be prompted to authenticate using your Docker Hub password. If you specified the correct password, authentication should succeed.

Note: If your Docker registry username is different from the local username you used to create the image, you will have to tag your image with your registry username. For the example given in the last step, you would type:

docker tag j2hoon85/ubuntu-nodejs j2hoon85/ubuntu-nodejs

Then you can push your own image using:

docker push j2hoon85/ubuntu-nodejs

To push the ubuntu-nodejs image to the sammy repository, the command would be:

docker push j2hoon85/ubuntu-nodejs
The push refers to repository [docker.io/j2hoon85/ubuntu-nodejs]
7159bda7f8e1: Pushed
b9b7103af585: Mounted from library/ubuntu
ca2991e4676c: Mounted from library/ubuntu
a768c3f3878e: Mounted from library/ubuntu
bc7f4b25d0ae: Mounted from library/ubuntu
latest: digest: sha256:a53344a922590465bd75afd1419c732392796392f25642eb1ef58b9dfbec05f8 size: 1362

The process may take some time to complete as it uploads the images, but when completed, the output will look like this:

%23%20Docker%20installation%20on%20GCP%0A@%28docker%29%5B%uB3C4%uCEE4%7CGCP%7C%uD2F0%uC2A4%uD1A0%uB9AC%5D%0A%0AWe%20are%20going%20to%20learn%20the%20way%20to%20set%20up%20and%20install%20docker%20on%20google%20compute%20engine.%20%0A%0A----------%0A%0A%5BTOC%5D%0A%0A%23%23%20Step%201.%20Create%20a%20new%20Google%20Compute%20Engine%20%28GCE%29%20instance%0A1.%20Go%20to%20your%20Google%20Cloud%20Platform%20console%0A2.%20Create%20a%20new%20Google%20Compute%20Engine%2C%20with%20Debian%208%20or%20Linux%20distort%20of%20your%20choice.%0A%09+%20Give%20it%20a%20name%0A%09+%20Choose%20a%20zone%0A%09+%20Choose%20a%20machine%20type%0A%09+%20Allow%20HTTP%20traffic%0A%09+%20Click%20%u201CCreate%u201D%20%0A%0A3.%20SSH%20into%20your%20new%20Google%20Compute%20Engine%0A%0A%23%23%20Step%202.%20Install%20Docker%20on%20your%20new%20Google%20Compute%20Engine%20Machine%0A1.%20Login%20as%20Super%20user%0A%09+%20sudo%20-s%0A%0A2.%20First%2C%20in%20order%20to%20ensure%20the%20downloads%20are%20valid%2C%20add%20the%20GPG%20key%20for%20the%20official%20Docker%20repository%20to%20your%20system%3A%0A%60%60%60powershell%0Acurl%20-fsSL%20https%3A//download.docker.com/linux/ubuntu/gpg%20%7C%20sudo%20apt-key%20add%20-%0A%60%60%60%0A%0A3.%20Add%20the%20Docker%20repository%20to%20APT%20sources%3A%0A%60%60%60powershell%0Asudo%20add-apt-repository%20%22deb%20%5Barch%3Damd64%5D%20https%3A//download.docker.com/linux/ubuntu%20%24%28lsb_release%20-cs%29%20stable%22%0A%60%60%60%0A%0A4.%20Next%2C%20update%20the%20package%20database%20with%20the%20Docker%20packages%20from%20the%20newly%20added%20repo%3A%0A%60%60%60powershell%0Asudo%20apt-get%20update%0A%60%60%60%0A%3E%20docker-ce%3A%0A%20%20Installed%3A%20%28none%29%0A%20%20Candidate%3A%205%3A18.09.0%7E3-0%7Eubuntu-xenial%0A%20%20Version%20table%3A%0A%20%20%20%20%205%3A18.09.0%7E3-0%7Eubuntu-xenial%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2018.06.1%7Ece%7E3-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2018.06.0%7Ece%7E3-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2018.03.1%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2018.03.0%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.12.1%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.12.0%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.09.1%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.09.0%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.06.2%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.06.1%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.06.0%7Ece-0%7Eubuntu%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.03.3%7Ece-0%7Eubuntu-xenial%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.03.2%7Ece-0%7Eubuntu-xenial%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.03.1%7Ece-0%7Eubuntu-xenial%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%20%20%20%20%2017.03.0%7Ece-0%7Eubuntu-xenial%20500%0A%20%20%20%20%20%20%20%20500%20https%3A//download.docker.com/linux/ubuntu%20xenial/stable%20amd64%20Packages%0A%0A5.%20Finally%2C%20install%20Docker%3A%0A%60%60%60powershell%0Asudo%20apt-get%20install%20-y%20docker-ce%0A%60%60%60%0A%0A6.%20Docker%20should%20now%20be%20installed%2C%20the%20daemon%20started%2C%20and%20the%20process%20enabled%20to%20start%20on%20boot.%20Check%20that%20it%27s%20running%3A%0A%60%60%60powershell%0Asudo%20systemctl%20status%20docker%0A%60%60%60%0A%3E%20%u25CF%20docker.service%20-%20Docker%20Application%20Container%20Engine%0A%20%20%20Loaded%3A%20loaded%20%28/lib/systemd/system/docker.service%3B%20enabled%3B%20vendor%20preset%3A%20enabled%29%0A%20%20%20Active%3A%20active%20%28running%29%20since%20Thu%202018-12-27%2015%3A50%3A28%20UTC%3B%2039s%20ago%0A%20%20%20%20%20Docs%3A%20https%3A//docs.docker.com%0A%20Main%20PID%3A%2014035%20%28dockerd%29%0A%20%20%20CGroup%3A%20/system.slice/docker.service%0A%20%20%20%20%20%20%20%20%20%20%20%u2514%u250014035%20/usr/bin/dockerd%20-H%20unix%3A//%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.226811162Z%22%20level%3Dwarning%20msg%3D%22Your%20kernel%20does%20not%20support%20swap%20memory%20limit%22%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.227267680Z%22%20level%3Dwarning%20msg%3D%22Your%20kernel%20does%20not%20support%20cgroup%20rt%20period%22%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.227457038Z%22%20level%3Dwarning%20msg%3D%22Your%20kernel%20does%20not%20support%20cgroup%20rt%20runtime%22%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.229318131Z%22%20level%3Dinfo%20msg%3D%22Loading%20containers%3A%20start.%22%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.712759962Z%22%20level%3Dinfo%20msg%3D%22Default%20bridge%20%28docker0%29%20is%20assigned%20with%20an%20IP%20address%20172.17.0.0/16.%20Daemon%20opti%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.796363894Z%22%20level%3Dinfo%20msg%3D%22Loading%20containers%3A%20done.%22%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.840844599Z%22%20level%3Dinfo%20msg%3D%22Docker%20daemon%22%20commit%3D4d60db4%20graphdriver%28s%29%3Doverlay2%20version%3D18.09.0%0ADec%2027%2015%3A50%3A27%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A27.841562244Z%22%20level%3Dinfo%20msg%3D%22Daemon%20has%20completed%20initialization%22%0ADec%2027%2015%3A50%3A28%20database-server%20systemd%5B1%5D%3A%20Started%20Docker%20Application%20Container%20Engine.%0ADec%2027%2015%3A50%3A28%20database-server%20dockerd%5B14035%5D%3A%20time%3D%222018-12-27T15%3A50%3A28.050783220Z%22%20level%3Dinfo%20msg%3D%22API%20listen%20on%20/var/run/docker.sock%22%0A%0A%23%23%20Step%203.%20Executing%20the%20Docker%20Command%20Without%20Sudo%20%28Optional%29%0A1.%20If%20you%20want%20to%20avoid%20typing%20sudo%20whenever%20you%20run%20the%20docker%20command%2C%20add%20your%20username%20to%20the%20docker%20group%3A%0A%60%60%60powershell%0Asudo%20groupadd%20docker%0Asudo%20usermod%20-aG%20docker%20%24%7BUSER%7D%0A%60%60%60%0A2.%20To%20apply%20the%20new%20group%20membership%2C%20you%20can%20log%20out%20of%20the%20server%20and%20back%20in%2C%20or%20you%20can%20type%20the%20following%3A%0A%60%60%60powershell%0Asudo%20passwd%20root%0Asu%20-%20%24%7BUSER%7D%0A%60%60%60%0A3.%20You%20will%20be%20prompted%20to%20enter%20your%20user%27s%20password%20to%20continue.%20Afterwards%2C%20you%20can%20confirm%20that%20your%20user%20is%20now%20added%20to%20the%20docker%20group%20by%20typing%3A%0A%60%60%60powershell%0Aid%20-nG%0A%60%60%60%0A%0A%23%23%20Step%204.%20Working%20with%20Docker%20Images%0A%60%60%60powershell%0Adocker%20run%20hello-world%0A%60%60%60%0A%3E%20Hello%20from%20Docker%21%0AThis%20message%20shows%20that%20your%20installation%20appears%20to%20be%20working%20correctly.%0A%0A%3E%20To%20generate%20this%20message%2C%20Docker%20took%20the%20following%20steps%3A%0A%201.%20The%20Docker%20client%20contacted%20the%20Docker%20daemon.%0A%202.%20The%20Docker%20daemon%20pulled%20the%20%22hello-world%22%20image%20from%20the%20Docker%20Hub.%0A%20%20%20%20%28amd64%29%0A%203.%20The%20Docker%20daemon%20created%20a%20new%20container%20from%20that%20image%20which%20runs%20the%0A%20%20%20%20executable%20that%20produces%20the%20output%20you%20are%20currently%20reading.%0A%204.%20The%20Docker%20daemon%20streamed%20that%20output%20to%20the%20Docker%20client%2C%20which%20sent%20it%0A%20%20%20%20to%20your%20terminal.%0A%0A%3E%20To%20try%20something%20more%20ambitious%2C%20you%20can%20run%20an%20Ubuntu%20container%20with%3A%0A%0A%60%60%60powershell%0Adocker%20run%20-it%20ubuntu%20bash%0A%60%60%60%0A%3E%20output%0A%60%60%60powershell%0AUnable%20to%20find%20image%20%27ubuntu%3Alatest%27%20locally%0Alatest%3A%20Pulling%20from%20library/ubuntu%0A32802c0cfa4d%3A%20Pull%20complete%20%0Ada1315cffa03%3A%20Pull%20complete%20%0Afa83472a3562%3A%20Pull%20complete%20%0Af85999a86bef%3A%20Pull%20complete%20%0ADigest%3A%20sha256%3A6d0e0c26489e33f5a6f0020edface2727db9489744ecc9b4f50c7fa671f23c49%0AStatus%3A%20Downloaded%20newer%20image%20for%20ubuntu%3Alatest%0Aroot@ffc2620c415b%3A/%23%20exit%0Aexit%0A%60%60%60%0A%0A%0A%0A%3E%20Share%20images%2C%20automate%20workflows%2C%20and%20more%20with%20a%20free%20Docker%20ID%3A%0A%3E%20https%3A//hub.docker.com/%0A%0A%3E%20For%20more%20examples%20and%20ideas%2C%20visit%3A%0A%3E%20https%3A//docs.docker.com/get-started/%0A%0A%60%60%60powershell%0Adocker%20images%0A%60%60%60%0A%3E%20output%0A%0A%60%60%60powershell%0AREPOSITORY%20%20%20%20%20%20%20%20%20%20TAG%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20IMAGE%20ID%20%20%20%20%20%20%20%20%20%20%20%20CREATED%20%20%20%20%20%20%20%20%20%20%20%20%20SIZE%0Aubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20latest%20%20%20%20%20%20%20%20%20%20%20%20%20%2093fd78260bd1%20%20%20%20%20%20%20%205%20weeks%20ago%20%20%20%20%20%20%20%20%2086.2MB%0Ahello-world%20%20%20%20%20%20%20%20%20latest%20%20%20%20%20%20%20%20%20%20%20%20%20%204ab4c602aa5e%20%20%20%20%20%20%20%203%20months%20ago%20%20%20%20%20%20%20%201.84kB%0A%60%60%60%0A%0A%23%23%20Step%205.%20Running%20a%20Docker%20Container%0AContainers%20can%20be%20much%20more%20useful%20than%20that%2C%20and%20they%20can%20be%20interactive.%20After%20all%2C%20they%20are%20similar%20to%20virtual%20machines%2C%20only%20more%20resource-friendly.%0AAs%20an%20example%2C%20let%27s%20run%20a%20container%20using%20the%20latest%20image%20of%20Ubuntu.%20The%20combination%20of%20the%20-i%20and%20-t%20switches%20gives%20you%20interactive%20shell%20access%20into%20the%20container%3A%0A%60%60%60powershell%0Adocker%20run%20-it%20ubuntu%0A%60%60%60%0A%3E%20output%0A%0A%60%60%60powershell%0Aroot@f39fe297ef16%3A/%23%20apt-get%20update%0AGet%3A1%20http%3A//security.ubuntu.com/ubuntu%20bionic-security%20InRelease%20%5B83.2%20kB%5D%0AGet%3A2%20http%3A//archive.ubuntu.com/ubuntu%20bionic%20InRelease%20%5B242%20kB%5D%0AGet%3A3%20http%3A//security.ubuntu.com/ubuntu%20bionic-security/universe%20amd64%20Packages%20%5B135%20kB%5D%0AGet%3A4%20http%3A//archive.ubuntu.com/ubuntu%20bionic-updates%20InRelease%20%5B88.7%20kB%5D%20%20%20%20%20%20%20%0AGet%3A5%20http%3A//archive.ubuntu.com/ubuntu%20bionic-backports%20InRelease%20%5B74.6%20kB%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AGet%3A6%20http%3A//security.ubuntu.com/ubuntu%20bionic-security/multiverse%20amd64%20Packages%20%5B1367%20B%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AGet%3A7%20http%3A//security.ubuntu.com/ubuntu%20bionic-security/main%20amd64%20Packages%20%5B300%20kB%5D%0AGet%3A8%20http%3A//archive.ubuntu.com/ubuntu%20bionic/universe%20amd64%20Packages%20%5B11.3%20MB%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AGet%3A9%20http%3A//archive.ubuntu.com/ubuntu%20bionic/restricted%20amd64%20Packages%20%5B13.5%20kB%5D%20%0AGet%3A10%20http%3A//archive.ubuntu.com/ubuntu%20bionic/main%20amd64%20Packages%20%5B1344%20kB%5D%0AGet%3A11%20http%3A//archive.ubuntu.com/ubuntu%20bionic/multiverse%20amd64%20Packages%20%5B186%20kB%5D%0AGet%3A12%20http%3A//archive.ubuntu.com/ubuntu%20bionic-updates/multiverse%20amd64%20Packages%20%5B6931%20B%5D%0AGet%3A13%20http%3A//archive.ubuntu.com/ubuntu%20bionic-updates/universe%20amd64%20Packages%20%5B900%20kB%5D%0AGet%3A14%20http%3A//archive.ubuntu.com/ubuntu%20bionic-updates/main%20amd64%20Packages%20%5B618%20kB%5D%0AGet%3A15%20http%3A//archive.ubuntu.com/ubuntu%20bionic-updates/restricted%20amd64%20Packages%20%5B10.7%20kB%5D%0AGet%3A16%20http%3A//archive.ubuntu.com/ubuntu%20bionic-backports/universe%20amd64%20Packages%20%5B3655%20B%5D%0AFetched%2015.3%20MB%20in%203s%20%285453%20kB/s%29%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AReading%20package%20lists...%20Done%0A%60%60%60%0A%0AThen%20install%20any%20application%20in%20it.%20Let%27s%20install%20Node.js%3A%0A%60%60%60powershell%0Aapt-get%20install%20-y%20nodejs%0A%60%60%60%0A%0AThis%20installs%20Node.js%20in%20the%20container%20from%20the%20official%20Ubuntu%20repository.%20When%20the%20installation%20finishes%2C%20verify%20that%20Node.js%20is%20installed%3A%0A%60%60%60powershell%0Anode%20-v%0A%60%60%60%0A%3E%20Output%0Av8.10.0%0A%0A%23%23%20Step%206.%20Managing%20Docker%20Containers%0AAfter%20using%20Docker%20for%20a%20while%2C%20you%27ll%20have%20many%20active%20%28running%29%20and%20inactive%20containers%20on%20your%20computer.%20To%20view%20the%20active%20ones%2C%20use%3A%0A%60%60%60powershell%0Adocker%20ps%0A%60%60%60%0AYou%20will%20see%20output%20similar%20to%20the%20following%3A%20%0A%3E%20output%0A%60%60%60powershell%0ACONTAINER%20ID%20%20%20%20%20%20%20%20IMAGE%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20COMMAND%20%20%20%20%20%20%20%20%20%20%20%20%20CREATED%20%20%20%20%20%20%20%20%20%20%20%20%20STATUS%20%20%20%20%20%20%20%20%20%20%20%20%20%20PORTS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20NAMES%0A%60%60%60%0A%0ATo%20view%20all%20containers%20%u2014%20active%20and%20inactive%20%u2014%20run%20docker%20ps%20with%20the%20-a%20switch%3A%0A%60%60%60powershell%0Adocker%20ps%20-a%0A%60%60%60%0A%3E%20output%0A%60%60%60powershell%0ACONTAINER%20ID%20%20%20%20%20%20%20%20IMAGE%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20COMMAND%20%20%20%20%20%20%20%20%20%20%20%20%20CREATED%20%20%20%20%20%20%20%20%20%20%20%20%20STATUS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20PORTS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20NAMES%0Af39fe297ef16%20%20%20%20%20%20%20%20ubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22/bin/bash%22%20%20%20%20%20%20%20%20%209%20hours%20ago%20%20%20%20%20%20%20%20%20Exited%20%280%29%208%20hours%20ago%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20thirsty_turing%0Ac5451bf09731%20%20%20%20%20%20%20%20ubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22/bin/bash%22%20%20%20%20%20%20%20%20%209%20hours%20ago%20%20%20%20%20%20%20%20%20Exited%20%280%29%209%20hours%20ago%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20nostalgic_archimedes%0Affc2620c415b%20%20%20%20%20%20%20%20ubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bash%22%20%20%20%20%20%20%20%20%20%20%20%20%20%209%20hours%20ago%20%20%20%20%20%20%20%20%20Exited%20%280%29%209%20hours%20ago%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20unruffled_wright%0A%60%60%60%0A%0ATo%20view%20the%20latest%20container%20you%20created%2C%20pass%20it%20the%20-l%20switch%3A%0A%60%60%60powershell%0Adocker%20ps%20-l%0A%60%60%60%0A%0A%3E%20output%0A%60%60%60powershell%0ACONTAINER%20ID%20%20%20%20%20%20%20%20IMAGE%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20COMMAND%20%20%20%20%20%20%20%20%20%20%20%20%20CREATED%20%20%20%20%20%20%20%20%20%20%20%20%20STATUS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20PORTS%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20NAMES%0Af39fe297ef16%20%20%20%20%20%20%20%20ubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22/bin/bash%22%20%20%20%20%20%20%20%20%209%20hours%20ago%20%20%20%20%20%20%20%20%20Exited%20%280%29%208%20hours%20ago%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20thirsty_turing%0A%60%60%60%0A%0ATo%20start%20a%20stopped%20container%2C%20use%20docker%20start%2C%20followed%20by%20the%20container%20ID%20or%20the%20container%27s%20name.%20Let%27s%20start%20the%20Ubuntu-based%20container%20with%20the%20ID%20of%20%3A%0A%60%60%60powershell%0Adocker%20start%20f39fe297ef16%0A%60%60%60%0ATo%20stop%20a%20running%20container%2C%20use%20docker%20stop%2C%20followed%20by%20the%20container%20ID%20or%20name.%20This%20time%2C%20we%27ll%20use%20the%20name%20that%20Docker%20assigned%20the%20container%2C%20which%20is%20thirsty_turing.%20%0A%60%60%60powershell%0Adocker%20stop%20thirsty_turing%0A%60%60%60%0A%0AOnce%20you%27ve%20decided%20you%20no%20longer%20need%20a%20container%20anymore%2C%20remove%20it%20with%20the%20docker%20rm%20command%2C%20again%20using%20either%20the%20container%20ID%20or%20the%20name.%20Use%20the%20docker%20ps%20-a%20command%20to%20find%20the%20container%20ID%20or%20name%20for%20the%20container%20associated%20with%20the%20hello-world%20image%20and%20remove%20it.%0A%60%60%60powershell%0Adocker%20rm%20thirsty_turing%0A%60%60%60%0A%0A%23%23%20Step%207.%20Committing%20Changes%20in%20a%20Container%20to%20a%20Docker%20Image%0AThis%20section%20shows%20you%20how%20to%20save%20the%20state%20of%20a%20container%20as%20a%20new%20Docker%20image.%0A%60%60%60powershell%0Adocker%20commit%20-m%20%22What%20did%20you%20do%20to%20the%20image%22%20-a%20%22Author%20Name%22%20container-id%20repository/new_image_name%0A%60%60%60%0AThe%20**-m**%20switch%20is%20for%20the%20commit%20message%20that%20helps%20you%20and%20others%20know%20what%20changes%20you%20made%2C%20while%20**-a**%20is%20used%20to%20specify%20the%20author.%20The%20**container%20ID**%20is%20the%20one%20you%20noted%20earlier%20in%20the%20tutorial%20when%20you%20started%20the%20interactive%20Docker%20session.%20Unless%20you%20created%20additional%20repositories%20on%20Docker%20Hub%2C%20the%20repository%20is%20**usually%20your%20Docker%20Hub%20username.**%0A%0AFor%20example%2C%20for%20the%20user%20j2hoon85%2C%20with%20the%20container%20ID%20of%20a2cd48b54e5c%2C%20the%20command%20would%20be%3A%0A%60%60%60powershell%0Adocker%20commit%20-m%20%22added%20node.js%22%20-a%20%22j2hoon85%22%20a2cd48b54e5c%20j2hoon85/ubuntu-nodejs%0A%60%60%60%0A%0A%60%60%60powershell%0Adocker%20images%0A%0AREPOSITORY%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TAG%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20IMAGE%20ID%20%20%20%20%20%20%20%20%20%20%20%20CREATED%20%20%20%20%20%20%20%20%20%20%20%20%20SIZE%0Aj2hoon85/ubuntu-nodejs%20%20%20latest%20%20%20%20%20%20%20%20%20%20%20%20%20%20b318da5e1778%20%20%20%20%20%20%20%209%20seconds%20ago%20%20%20%20%20%20%20170MB%0Aubuntu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20latest%20%20%20%20%20%20%20%20%20%20%20%20%20%2093fd78260bd1%20%20%20%20%20%20%20%205%20weeks%20ago%20%20%20%20%20%20%20%20%2086.2MB%0Ahello-world%20%20%20%20%20%20%20%20%20%20%20%20%20%20latest%20%20%20%20%20%20%20%20%20%20%20%20%20%204ab4c602aa5e%20%20%20%20%20%20%20%203%20months%20ago%20%20%20%20%20%20%20%201.84kB%0A%60%60%60%0AIn%20the%20above%20example%2C%20ubuntu-nodejs%20is%20the%20new%20image%2C%20which%20was%20derived%20from%20the%20existing%20ubuntu%20image%20from%20Docker%20Hub.%20The%20size%20difference%20reflects%20the%20changes%20that%20were%20made.%20In%20this%20example%2C%20the%20change%20was%20that%20Node.js%20was%20installed.%20Next%20time%20you%20need%20to%20run%20a%20container%20using%20Ubuntu%20with%20Node.js%20pre-installed%2C%20you%20can%20just%20use%20the%20new%20image.%0A%0A%23%23%20Step%208.%20Pushing%20Docker%20Images%20to%20a%20Docker%20Repository%0ATo%20push%20an%20image%20to%20Docker%20Hub%20or%20any%20other%20Docker%20registry%2C%20you%20must%20have%20an%20account%20there.%0AThis%20section%20shows%20you%20how%20to%20push%20a%20Docker%20image%20to%20Docker%20Hub.%20To%20learn%20how%20to%20create%20your%20own%20private%20Docker%20registry%2C%20check%20out%20%5BHow%20To%20Set%20Up%20a%20Private%20Docker%20Registry%20on%20Ubuntu%2014.04%5D%5B1%5D.%0A%60%60%60powershell%0Adocker%20login%20-u%20j2hoon85%0A%60%60%60%0AYou%27ll%20be%20prompted%20to%20authenticate%20using%20your%20Docker%20Hub%20password.%20If%20you%20specified%20the%20correct%20password%2C%20authentication%20should%20succeed.%20%0A%0A%3E%20Note%3A%20If%20your%20Docker%20registry%20username%20is%20different%20from%20the%20local%20username%20you%20used%20to%20create%20the%20image%2C%20you%20will%20have%20to%20tag%20your%20image%20with%20your%20registry%20username.%20For%20the%20example%20given%20in%20the%20last%20step%2C%20you%20would%20type%3A%0A%60%60%60powershell%0Adocker%20tag%20j2hoon85/ubuntu-nodejs%20j2hoon85/ubuntu-nodejs%0A%60%60%60%0AThen%20you%20can%20push%20your%20own%20image%20using%3A%0A%60%60%60powershell%0Adocker%20push%20j2hoon85/ubuntu-nodejs%0A%60%60%60%0ATo%20push%20the%20ubuntu-nodejs%20image%20to%20the%20sammy%20repository%2C%20the%20command%20would%20be%3A%0A%60%60%60powershell%0Adocker%20push%20j2hoon85/ubuntu-nodejs%0A%0AThe%20push%20refers%20to%20repository%20%5Bdocker.io/j2hoon85/ubuntu-nodejs%5D%0A7159bda7f8e1%3A%20Pushed%20%0Ab9b7103af585%3A%20Mounted%20from%20library/ubuntu%20%0Aca2991e4676c%3A%20Mounted%20from%20library/ubuntu%20%0Aa768c3f3878e%3A%20Mounted%20from%20library/ubuntu%20%0Abc7f4b25d0ae%3A%20Mounted%20from%20library/ubuntu%20%0Alatest%3A%20digest%3A%20sha256%3Aa53344a922590465bd75afd1419c732392796392f25642eb1ef58b9dfbec05f8%20size%3A%201362%0A%60%60%60%0AThe%20process%20may%20take%20some%20time%20to%20complete%20as%20it%20uploads%20the%20images%2C%20but%20when%20completed%2C%20the%20output%20will%20look%20like%20this%3A%0A%0A%21%5BAlt%20text%5D%28./docker_image.png%29%0A%0A%0A%0A%0A%5B1%5D%3Ahttps%3A//www.digitalocean.com/community/tutorials/how-to-set-up-a-private-docker-registry-on-ubuntu-14-04


The source codes and contents come from the E-Learning DataCamp: Sentiment Analysis in R: The Tidy Way Enjoy

Intro

  • The next real-world text exploration uses tragedies and comedies by Shakespeare to show how sentiment analysis can lead to insight into differences in word use. You will learn how to transform raw text into a tidy format for further analysis.

1. To be, or not to be

  • The shakespeare dataset contains three columns:
    • title, the title of a Shakespearean play,
    • type, the type of play, either tragedy or comedy, and
    • text, a line from that play. This data frame contains the entire texts of six plays.
library(tidytext)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
load("data/shakespeare.rda")
glimpse(shakespeare)
## Observations: 25,888
## Variables: 3
## $ title <chr> "The Tragedy of Romeo and Juliet", "The Tragedy of Romeo...
## $ type <chr> "Tragedy", "Tragedy", "Tragedy", "Tragedy", "Tragedy", "...
## $ text <chr> "The Complete Works of William Shakespeare", "", "The Tr...
# Use count to find out how many titles/types there are
shakespeare %>%
count(title, type)
## # A tibble: 6 x 3
## title type n
## <chr> <chr> <int>
## 1 A Midsummer Night's Dream Comedy 3459
## 2 Hamlet, Prince of Denmark Tragedy 6776
## 3 Much Ado about Nothing Comedy 3799
## 4 The Merchant of Venice Comedy 4225
## 5 The Tragedy of Macbeth Tragedy 3188
## 6 The Tragedy of Romeo and Juliet Tragedy 4441

2. Unnesting from text to word

he shakespeare dataset is not yet compatible with tidy tools. You need to first break the text into individual tokens (the process of tokenization); a token is a meaningful unit of text for analysis, in many cases, just synonymous with a single word. You also need to transform the text to a tidy data structure with one token per row. You can use tidytext’s unnest_tokens() function to accomplish all of this at once.

library(tidytext)
tidy_shakespeare <- shakespeare %>%
group_by(title) %>%
mutate(linenumber = row_number()) %>%
unnest_tokens(word, text) %>% # Transform the non-tidy text data to tidy text data
ungroup()
tidy_shakespeare %>%
count(word, sort = TRUE)
## # A tibble: 10,736 x 2
## word n
## <chr> <int>
## 1 the 4651
## 2 and 4170
## 3 i 3296
## 4 to 3047
## 5 of 2645
## 6 a 2511
## 7 you 2287
## 8 my 1913
## 9 in 1836
## 10 that 1721
## # ... with 10,726 more rows
  • Notice how the most common words in the data frame are words like “the”, “and”, and “i” that have no sentiments associated with them. In the next exercise, you’ll join the data with a lexicon to implement sentiment analysis.

3. Sentiment analysis of Shakespeare

After transforming the text of these Shakespearean plays to a tidy text dataset in the last exercise, the resulting data frame tidy_shakespeare is ready for sentiment analysis with such an approach. Once you have performed the sentiment analysis, you can find out how many negative and positive words each play has with just one line of code.

shakespeare_sentiment <- tidy_shakespeare %>%
inner_join(get_sentiments("bing")) # Implement sentiment analysis with the "bing" lexicon
## Joining, by = "word"
shakespeare_sentiment %>%
count(title, sentiment) # Find how many positive/negative words each play has
## # A tibble: 12 x 3
## title sentiment n
## <chr> <chr> <int>
## 1 A Midsummer Night's Dream negative 681
## 2 A Midsummer Night's Dream positive 773
## 3 Hamlet, Prince of Denmark negative 1323
## 4 Hamlet, Prince of Denmark positive 1223
## 5 Much Ado about Nothing negative 767
## 6 Much Ado about Nothing positive 1127
## 7 The Merchant of Venice negative 740
## 8 The Merchant of Venice positive 962
## 9 The Tragedy of Macbeth negative 914
## 10 The Tragedy of Macbeth positive 749
## 11 The Tragedy of Romeo and Juliet negative 1235
## 12 The Tragedy of Romeo and Juliet positive 1090
  • Passing two variables to count() returns the count n for each unique combination of the two variables. In this case, you have 6 plays and 2 sentiments, so count() returns 6 x 2 = 12 rows.

4. Tragedy or comedy?

  • Which plays have a higher percentage of negative words? Do the tragedies have more negative words than the comedies?
sentiment_counts <- tidy_shakespeare %>%
inner_join(get_sentiments("bing")) %>%
# Count the number of words by title, type, and sentiment
count(title, type, sentiment)
## Joining, by = "word"
sentiment_counts %>%
group_by(title) %>% # Group by the titles of the plays
mutate(total = sum(n), # Find the total number of words in each play
percent = n / total) %>% # Calculate the number of words divided by the total
filter(sentiment == "negative") %>% # Filter the results for only negative sentiment
arrange(percent)
## # A tibble: 6 x 6
## # Groups: title [6]
## title type sentiment n total percent
## <chr> <chr> <chr> <int> <int> <dbl>
## 1 Much Ado about Nothing Comedy negative 767 1894 0.405
## 2 The Merchant of Venice Comedy negative 740 1702 0.435
## 3 A Midsummer Night's Dream Comedy negative 681 1454 0.468
## 4 Hamlet, Prince of Denmark Tragedy negative 1323 2546 0.520
## 5 The Tragedy of Romeo and Juliet Tragedy negative 1235 2325 0.531
## 6 The Tragedy of Macbeth Tragedy negative 914 1663 0.550
  • Looking at the percent column of your output, you can see that tragedies do in fact have a higher percentage of negative words!

5. Most common positive and negative words

  • Now you can explore which specific words are driving these sentiment scores. Which are the most common positive and negative words in these plays?
word_counts <- tidy_shakespeare %>%
inner_join(get_sentiments("bing")) %>%
count(word, sentiment)
## Joining, by = "word"
top_words <- word_counts %>%
group_by(sentiment) %>% # Group by sentiment
top_n(10) %>% # Take the top 10 for each sentiment
ungroup() %>% # Make word a factor in order of n
mutate(word = reorder(word, n))
## Selecting by n
# Use aes() to put words on the x-axis and n on the y-axis
library(ggplot2)
ggplot(top_words, aes(x = word, y = n, fill = sentiment)) +
geom_col(show.legend = FALSE) +
facet_wrap(~sentiment, scales = "free") +
coord_flip()

 

- Death is pretty negative and love is positive, but are there words in that list that had different connotations during Shakespeare’s time? Do you see a word that the lexicon has misidentified? - The word "wilt" was used differently in Shakespeare’s time and was not negative; the lexicon has misidentified it. For example, from Romeo and Juliet, "For thou wilt lie upon the wings of night". It is important to explore the details of how words were - cored when performing sentiment analyses.

6. Word contributions by play

  • You will also practice using a different sentiment lexicon, the “afinn” lexicon in which words have a score from -5 to 5. Different lexicons take different approaches to quantifying the emotion/opinion content of words.
  • Which words contribute to the overall sentiment in which plays?
tidy_shakespeare %>%
count(title, word, sort = TRUE) %>% # Count by title and word
inner_join(get_sentiments("afinn")) %>% # Implement sentiment analysis using the "afinn" lexicon
filter(title == "The Tragedy of Macbeth", score < 0) # Filter to only examine the scores for Macbeth that are negative
## Joining, by = "word"
## # A tibble: 237 x 4
## title word n score
## <chr> <chr> <int> <int>
## 1 The Tragedy of Macbeth no 73 -1
## 2 The Tragedy of Macbeth fear 35 -2
## 3 The Tragedy of Macbeth death 20 -2
## 4 The Tragedy of Macbeth bloody 16 -3
## 5 The Tragedy of Macbeth poor 16 -2
## 6 The Tragedy of Macbeth strange 16 -1
## 7 The Tragedy of Macbeth dead 14 -3
## 8 The Tragedy of Macbeth leave 14 -1
## 9 The Tragedy of Macbeth fight 13 -1
## 10 The Tragedy of Macbeth charges 11 -2
## # ... with 227 more rows
  • Notice the use of words specific to Macbeth like “bloody”.

7. Calculating a contribution score

  • you can calculate a relative contribution for each word in each play. This contribution can be found by multiplying the score for each word by the times it is used in each play and divided by the total words in each play.
sentiment_contributions <- tidy_shakespeare %>%
count(title, word, sort = TRUE) %>% # Count by title and word
inner_join(get_sentiments("afinn")) %>% # Implement sentiment analysis using the "afinn" lexicon
group_by(title) %>% # Group by title
mutate(contribution = (n * score) / sum(n)) %>% # Calculate a contribution for each word in each title
ungroup()
## Joining, by = "word"
sentiment_contributions
## # A tibble: 2,366 x 5
## title word n score contribution
## <chr> <chr> <int> <int> <dbl>
## 1 Hamlet, Prince of Denmark no 143 -1 -0.0652
## 2 The Tragedy of Romeo and Juliet love 140 3 0.213
## 3 Much Ado about Nothing no 132 -1 -0.0768
## 4 Much Ado about Nothing hero 114 2 0.133
## 5 A Midsummer Night's Dream love 110 3 0.270
## 6 Hamlet, Prince of Denmark good 109 3 0.149
## 7 The Tragedy of Romeo and Juliet no 102 -1 -0.0518
## 8 Much Ado about Nothing good 93 3 0.162
## 9 The Merchant of Venice no 92 -1 -0.0630
## 10 Much Ado about Nothing love 91 3 0.159
## # ... with 2,356 more rows
  • Notice that “hero” shows up in your results there; that is the name of one of the characters in “Much Ado About Nothing”.

8. Alas, poor Yorick!

  • It’s time to explore some of your results! Look at Hamlet and The Merchant of Venice to see what negative and positive words are important in these two plays.

  • Arrange the most negative words

sentiment_contributions %>%
# Filter for Hamlet
filter(title == "Hamlet, Prince of Denmark") %>%
# Arrange to see the most negative words
arrange(contribution)
## # A tibble: 493 x 5
## title word n score contribution
## <chr> <chr> <int> <int> <dbl>
## 1 Hamlet, Prince of Denmark no 143 -1 -0.0652
## 2 Hamlet, Prince of Denmark dead 33 -3 -0.0451
## 3 Hamlet, Prince of Denmark death 38 -2 -0.0347
## 4 Hamlet, Prince of Denmark madness 22 -3 -0.0301
## 5 Hamlet, Prince of Denmark mad 21 -3 -0.0287
## 6 Hamlet, Prince of Denmark fear 21 -2 -0.0192
## 7 Hamlet, Prince of Denmark poor 20 -2 -0.0182
## 8 Hamlet, Prince of Denmark hell 10 -4 -0.0182
## 9 Hamlet, Prince of Denmark grave 17 -2 -0.0155
## 10 Hamlet, Prince of Denmark ghost 32 -1 -0.0146
## # ... with 483 more rows
  • Arrange the most positive words
sentiment_contributions %>%
# Filter for Hamlet
filter(title == "The Merchant of Venice") %>%
# Arrange to see the most negative words
arrange(desc(contribution))
## # A tibble: 344 x 5
## title word n score contribution
## <chr> <chr> <int> <int> <dbl>
## 1 The Merchant of Venice good 63 3 0.129
## 2 The Merchant of Venice love 60 3 0.123
## 3 The Merchant of Venice fair 35 2 0.0479
## 4 The Merchant of Venice like 34 2 0.0466
## 5 The Merchant of Venice true 24 2 0.0329
## 6 The Merchant of Venice sweet 23 2 0.0315
## 7 The Merchant of Venice pray 42 1 0.0288
## 8 The Merchant of Venice better 21 2 0.0288
## 9 The Merchant of Venice justice 17 2 0.0233
## 10 The Merchant of Venice welcome 17 2 0.0233
## # ... with 334 more rows
  • These are definitely characteristic words for these two plays.

9. Sentiment changes through a play

  • We will start by first implementing sentiment analysis using inner_join(), and then use count() with four arguments:
    • title,
    • type,
    • an index that will section together lines of the play, and
    • sentiment.
  • After these lines of code, you will have the number of positive and negative words used in each index-ed section of the play. These sections will be 70 lines long in your analysis here. You want a chunk of text that is not too small (because then the sentiment changes will be very noisy) and not too big (because then you will not be able to see plot structure). In an analysis of this type you may need to experiment with what size chunks to make; sections of 70 lines works well for these plays.
tidy_shakespeare %>%
inner_join(get_sentiments("bing")) %>% # Implement sentiment analysis using "bing" lexicon
count(title,
type,
index = linenumber %/% 70,
sentiment)
## Joining, by = "word"
## # A tibble: 744 x 5
## title type index sentiment n
## <chr> <chr> <dbl> <chr> <int>
## 1 A Midsummer Night's Dream Comedy 0 negative 4
## 2 A Midsummer Night's Dream Comedy 0 positive 11
## 3 A Midsummer Night's Dream Comedy 1 negative 7
## 4 A Midsummer Night's Dream Comedy 1 positive 19
## 5 A Midsummer Night's Dream Comedy 2 negative 20
## 6 A Midsummer Night's Dream Comedy 2 positive 23
## 7 A Midsummer Night's Dream Comedy 3 negative 12
## 8 A Midsummer Night's Dream Comedy 3 positive 18
## 9 A Midsummer Night's Dream Comedy 4 negative 9
## 10 A Midsummer Night's Dream Comedy 4 positive 27
## # ... with 734 more rows
  • This is the first step in looking at narrative arcs.

10. Calculating net sentiment

The next steps involve spread() from the tidyr package. After these lines of code, you will have the net sentiment in each index-ed section of the play; net sentiment is the negative sentiment subtracted from the positive sentiment.

# Load the tidyr package
library(tidyr)
tidy_shakespeare %>%
inner_join(get_sentiments("bing")) %>%
count(title, type, index = linenumber %/% 70, sentiment) %>%
spread(sentiment, n, fill = 0) %>% # Spread sentiment and n across multiple columns
mutate(sentiment = positive - negative) # Use mutate to find net sentiment
## Joining, by = "word"
## # A tibble: 373 x 6
## title type index negative positive sentiment
## <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 A Midsummer Night's Dream Comedy 0 4 11 7
## 2 A Midsummer Night's Dream Comedy 1 7 19 12
## 3 A Midsummer Night's Dream Comedy 2 20 23 3
## 4 A Midsummer Night's Dream Comedy 3 12 18 6
## 5 A Midsummer Night's Dream Comedy 4 9 27 18
## 6 A Midsummer Night's Dream Comedy 5 11 21 10
## 7 A Midsummer Night's Dream Comedy 6 12 16 4
## 8 A Midsummer Night's Dream Comedy 7 9 6 -3
## 9 A Midsummer Night's Dream Comedy 8 6 12 6
## 10 A Midsummer Night's Dream Comedy 9 19 12 -7
## # ... with 363 more rows

You are closer to plotting the sentiment through these plays.

11. Visualizing narrative arcs

you will continue to build on your manipulations of this text dataset and visualize the results of this sentiment analysis.

library(tidyr)
library(ggplot2)
tidy_shakespeare %>%
inner_join(get_sentiments("bing")) %>%
count(title, type, index = linenumber %/% 70, sentiment) %>%
spread(sentiment, n, fill = 0) %>%
mutate(sentiment = positive - negative) %>%
ggplot(aes(x = index, # Put index on x-axis
y = sentiment, # Put sentiment on y-axis
fill = type)) + # map comedy/tragedy to fill
geom_col() + # Make a bar chart with geom_col()
facet_wrap(~ title, scales = "free_x") # Separate panels for each title with facet_wrap()
## Joining, by = "word"


  • These plots show how sentiment changes through these plays. Notice how the comedies have happier endings and more positive sentiment than the tragedies.


'R > [R] Text Mining' 카테고리의 다른 글

Text Mining: Tweets Across the Unisted States From DataCamp  (0) 2018.12.20
Sentiment_Analysis_with_tidy_data  (0) 2018.12.20
The tidy text format  (0) 2018.12.18

+ Recent posts