How to make a Boxplot in R

Guest post by Grace Appell.

What is a Boxplot?

A box plot is a graph that helps you to analyze a set of data. It used to show the spread of the data. In it you use five data points: the minimum, the 1st quartile, the median, the 3rd quartile, and the maximum.
The minimum is the lowest point in your data set, and the maximum is the largest. The median is the number in the middle of the data set when you have the number lined up numerically.
For example if your data set was this:

 5, 6 ,11, 18, 12, 9, 4 

First you would put them in order lowest to highest.

4, 5, 6, 9, 11, 12, 18

Your median would be 9, because it is the middle number. The minimum would be 4, and the maximum would be 18.
The first quartile would be 5, the median of the numbers below 9, and the third quartile would be 12, the median of the numbers above 9.
So the data you would use in your boxplot would be

(4,5,9,12,18)

The boxplot would look like would look like this.

Example boxplot #1.
Example boxplot #1.

What is R?

R is a software program that is free to download that you can use for calculating statistics and creating graphics.
Here is their website: https://www.r-project.org/

Boxplots in R

In R you can create a boxplot by using this formula.

> Name of data set <- c(minimum, quartile 1, median, quartile 3, maximum)
> boxplot(Name of data set)

First you have to name your data set. In our project where we analyzed the number of times people repeated their Shakespeare lines that they performed, I used the name Macbeth. So the formula looked like this:

> Macbeth <- c(1,9,18,48,93)
> boxplot(Macbeth)

Using this data set, your box plot should look like this

Example boxplot #2.
Example boxplot #2.

Making 3D Periodic Tables

Laser cut, 3d periodic tables.
Laser cut, 3d periodic tables.

Ms. Fu’s chemistry class were given a project to make 3d periodic tables based on the properties of the elements. A few groups went with Makerspace options, using the new vinyl cutter and laser.

3d Periodic Table showing electronegativity.
3d Periodic Table showing electronegativity. Laser cut.
Periodic Table relief based on ionization energy. The blocks on this one have 1.5 inch square bases. The colors for the different regions  use stains including tea (assam) and blackberry juice extracted from berries from the canes on campus.
Periodic Table relief based on ionization energy. The blocks on this one have 1.5 inch square bases. The colors for the different regions use stains including tea (assam) and blackberry juice extracted from berries from the canes on campus.

The part that took the longest was marking all the columns for cutting. A worthwhile assignment would be to write a program to automatically make the cut-marks in an svg file that can be etched with the laser.

Periodic Table column heights based on density.
Periodic Table column heights based on density. Laser cut.
Paper columns and vinyl cut lettering on this periodic table.
Paper columns and vinyl cut lettering on this periodic table.

Thinking About Design Then Thinking About Culture

This year, as part of orientation, we showed a couple videos to students to get them thinking about the key questions:

  • Why are we here?
  • What do we want our culture to be like?
  • What do we need to do to make our culture the way we want it to be?

The one I showed, a TED talk by Tony Fadell focuses on how he sees the world as a designer: looking for those small nuisances to which we’ve become habituated by paying closer attention to detail, looking for the big picture, and trying to see things with new, childish eyes.

I think it was successful in that I’ve been hearing it come up–particularly the term habituation (although the students could often not remember the actual term)–a few times already this semester.

Programming Lesson: Distance Between Two Points

Assignment: Write a program to find the distance between two points.

To find the distance (c) between two points (x1, y1) and (x2, y2) you use the equation:

  c = \sqrt{a^2 + b^2}

where a and b are:

  a = x_2 - x_1
  b = y_2 - y_1

So, let’s find the distance between the points (1,7) and (5, 2) using python:

# define inputs
x1 = 1
y1 = 7
x2 = 5
y2 = 2

# calculate distance
a = x2 - x1
b = y2 - y1

c = (a**2 + b**2)**0.5   

# output the result
print("Distance between two points.")
print("Point 1:", x1, y1)
print("Point 2:", x2, y2)
print("Distance:", c)

The result should look like:

Distance between two points.
Point 1: 1 7
Point 2: 5 2
Distance: 6.40312

Coatis

Coati at the Pocosol Research Station in the Children's Eternal Rainforest , Costa Rica.
Coati at the Pocosol Research Station in the Children’s Eternal Rainforest , Costa Rica.

White-nosed Coatis (Nasua narica) are diurnal and, unusually for most Central America carnivores, highly social. They seem to fill a similar niche to raccoons. Ran into this one wandering around the Pocotal Research Station in the Bosque Eterno de los NiƱos, Costa Rica. It did not seem too perturbed that we were within 10 meters of each other.

Trophic Cascade: The Effect of Wolves on Yellowstone

The reintroduction of wolves to Yellowstone National Park resulted in enormous changes to the ecology: more plants and animals as the wolves reduced the deer population and changed the deers’ behavior. The change in vegetation resulted in stabilization of the rivers, so the wolves changed the geomorphology of the park as well.

Headless Pi Zero

Pi Zero‘s are even cheaper versions of the Raspberry Pi. The price you pay is that they’re harder to connect to since all the ports are small (micro-USB’s and mini-HDMI’s), so you need adapters to connect to keyboards, mice, and monitors. However, if you have the wireless version (Pi Zero W) you can set it up to automatically connect to the WiFi network, and work on it through there using the command line. This is a brief summary of how to do this (it’s called a “headless” setup) based on Taron Foxworth’s instructions. It should work for the full Raspberry Pi as well.

Set up the Operating System

You can install the Raspbian Stretch (or Raspbian Lite which does not include the desktop GUI that you will not use) on a SD card (I used 8 or 16 Gb cards).

  • Download Raspbian.
  • SD Card Formatter to format the SD Card. It’s pretty quick, just follow the instructions.
  • Etcher: to install the operating system on the SD Card

Set up automatic connection to WiFi

You may have to remove and reinsert the SD Card to get it to show up on the file system, but once you have you can set it up to automatically connect to WiFi by:

  • Go into the /boot partition (it usually shows up as the base of the SD Card on your file manager) and create a file named “ssh”.
  • Create a text file called “wpa_supplicant.conf” in the /boot folder, and put the following into it, assuming that the wifi router you’re connecting to is called “myWifi” and the password is “myPassword”.
  • country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
     ssid="myWifi"
     scan_ssid=1
     psk="myPassword"
     key_mgmt=WPA-PSK
    }
    

Now put the SD Card into the Pi and plug in the power.

Find the IP address

First you have to find the Pi on the local network. On Windows I use Cygwin to get something that looks and acts a bit like a unix terminal (on Mac you can use Terminal, or any shell window on Linux).

To find the ip address of your local network use:

on Windows:

> ipconfig

look for the “IPv4 Address”.

Mac (and Linux?)

> ifconfig

look under “en1:”

Connecting

To connect you use ssh on the command line (Mac or Linux) or something like Putty

Static IP

Without a static IP address it is possible that the Pi’s IP address will change occasionally. I followed the instructions on Circuit Basics and MODMYPI, but basically you have to:

  • Identify your network information:
    • Find your Gateway:
    • > route -ne
      
    • Find your Domain Server:
    • > cat /etc/resolv.conf
      
  • Add the information to the end of your /etc/dhcpcd.conf file (here the wlan0 means you’re doing this to the wireless interface (WiFi) and the static ip is 10.0.0.99, the static router the gateway ip you found above, and the domain_name_servers takes the domain server ip):
  • interface wlan0
    static ip_address=10.0.0.99
    static routers=10.0.0.1
    static domain_name_servers=75.75.75.75
    
  • Now reboot and you should be able to ssh or sftp into the new static IP.

A Web Server

Adding a webserver (apache with php) is pretty easy as well, just run the commands (from the Raspberry Pi Foundation)

Apache web server:

sudo apt-get install apache2 -y

PHP for server-side scripting

sudo apt-get install php libapache2-mod-php -y

Now your can find the webpage by going to the ip address (e.g. http://10.0.0.1).

The actual file that you’re seeing is located on the Pi at:

/var/www/html/index.html

You will probably need to change the ownership of the file in order to edit it by running:

> sudo chown pi: index.html