sna_eg_stanford:lab01
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sna_eg_stanford:lab01 [2019/12/11 08:31] – hkimscil | sna_eg_stanford:lab01 [2022/11/28 22:26] (current) – hkimscil | ||
---|---|---|---|
Line 82: | Line 82: | ||
# directly by referencing the URL in the read.table() function, | # directly by referencing the URL in the read.table() function, | ||
# as follows: | # as follows: | ||
- | advice_data_frame <- read.table(' | + | # advice_data_frame <- read.table(' |
- | friendship_data_frame <- read.table(' | + | # friendship_data_frame <- read.table(' |
- | reports_to_data_frame <- read.table(' | + | # reports_to_data_frame <- read.table(' |
- | + | ||
+ | advice_data_frame <- read.table(' | ||
+ | friendship_data_frame <- read.table(' | ||
+ | reports_to_data_frame <- read.table(' | ||
+ | |||
+ | |||
+ | |||
# If the files you want to work with are on your local machine, | # If the files you want to work with are on your local machine, | ||
# the easiest way to access them is to first set your working | # the easiest way to access them is to first set your working | ||
Line 114: | Line 121: | ||
# header=T, which tells R that the first row of data contains | # header=T, which tells R that the first row of data contains | ||
# column names. | # column names. | ||
- | attributes <- read.csv(' | + | # attributes <- read.csv(' |
+ | attributes <- read.csv(' | ||
attributes | attributes | ||
- | + | ||
# Other commands may be used to load data from files in different | # Other commands may be used to load data from files in different | ||
# formats. read.delim() is a general function for loading any | # formats. read.delim() is a general function for loading any | ||
Line 303: | Line 312: | ||
# example: setwd("/ | # example: setwd("/ | ||
- | setwd("" | + | # setwd("" |
| | ||
# First, let's plot the network with all possible ties. | # First, let's plot the network with all possible ties. | ||
pdf(" | pdf(" | ||
- | plot(krack_full) | + | plot(krack_full, main=" |
dev.off() | dev.off() | ||
Line 319: | Line 328: | ||
summary(krack_advice_only) | summary(krack_advice_only) | ||
pdf(" | pdf(" | ||
- | plot(krack_advice_only) | + | plot(krack_advice_only, main=" |
dev.off() | dev.off() | ||
Line 328: | Line 337: | ||
summary(krack_friendship_only) | summary(krack_friendship_only) | ||
pdf(" | pdf(" | ||
- | plot(krack_friendship_only) | + | plot(krack_friendship_only, main=" |
dev.off() | dev.off() | ||
Line 337: | Line 346: | ||
summary(krack_reports_to_only) | summary(krack_reports_to_only) | ||
pdf(" | pdf(" | ||
- | plot(krack_reports_to_only) | + | plot(krack_reports_to_only, main=" |
dev.off() | dev.off() | ||
Line 559: | Line 568: | ||
# To view your data in a spreadsheet-like window, use the command ' | # To view your data in a spreadsheet-like window, use the command ' | ||
- | fix(reports_to_data_frame) | + | # fix(reports_to_data_frame) |
# The attribute data for this lab is in a comma-separated-value | # The attribute data for this lab is in a comma-separated-value | ||
Line 608: | Line 617: | ||
# Take a look at each data frame using the ' | # Take a look at each data frame using the ' | ||
# need to close each fix window before R will evaluate the next line of code. | # need to close each fix window before R will evaluate the next line of code. | ||
- | fix(advice_data_frame) | + | |
- | fix(friendship_data_frame) | + | # fix(advice_data_frame) |
- | fix(reports_to_data_frame) | + | # fix(friendship_data_frame) |
+ | # fix(reports_to_data_frame) | ||
# Before we merge these data, we need to make sure ' | # Before we merge these data, we need to make sure ' | ||
Line 758: | Line 768: | ||
| | ||
# First, let's plot the network with all possible ties. | # First, let's plot the network with all possible ties. | ||
- | pdf(" | + | # pdf(" |
- | plot(krack_full) | + | plot(krack_full, main=" |
- | dev.off() | + | # dev.off() |
# This is a bit of a jumble, so let's look at the networks for | # This is a bit of a jumble, so let's look at the networks for | ||
Line 770: | Line 780: | ||
name = " | name = " | ||
summary(krack_advice_only) | summary(krack_advice_only) | ||
- | pdf(" | + | |
- | plot(krack_advice_only) | + | # pdf(" |
- | dev.off() | + | plot(krack_advice_only, main=" |
+ | # dev.off() | ||
# friendship only | # friendship only | ||
Line 779: | Line 790: | ||
name = " | name = " | ||
summary(krack_friendship_only) | summary(krack_friendship_only) | ||
- | pdf(" | + | # pdf(" |
- | plot(krack_friendship_only) | + | plot(krack_friendship_only, main=" |
- | dev.off() | + | # dev.off() |
# reports-to only | # reports-to only | ||
Line 788: | Line 799: | ||
name = " | name = " | ||
summary(krack_reports_to_only) | summary(krack_reports_to_only) | ||
- | pdf(" | + | # pdf(" |
- | plot(krack_reports_to_only) | + | plot(krack_reports_to_only, main=" |
- | dev.off() | + | # dev.off() |
# Still kind of messy, so let's clean things up a bit. For | # Still kind of messy, so let's clean things up a bit. For | ||
Line 802: | Line 813: | ||
reports_to_layout <- layout.fruchterman.reingold(krack_reports_to_only) | reports_to_layout <- layout.fruchterman.reingold(krack_reports_to_only) | ||
- | pdf(" | + | # pdf(" |
plot(krack_reports_to_only, | plot(krack_reports_to_only, | ||
- | | + | |
- | dev.off() | + | # dev.off() |
# Now let's color-code vertices by department and clean up the | # Now let's color-code vertices by department and clean up the | ||
Line 817: | Line 828: | ||
dept_vertex_colors[dept_vertex_colors == 4] = colors[5] | dept_vertex_colors[dept_vertex_colors == 4] = colors[5] | ||
- | pdf(" | + | # pdf(" |
plot(krack_reports_to_only, | plot(krack_reports_to_only, | ||
layout=reports_to_layout, | layout=reports_to_layout, | ||
vertex.color=dept_vertex_colors, | vertex.color=dept_vertex_colors, | ||
vertex.label=NA, | vertex.label=NA, | ||
- | edge.arrow.size=.5) | + | edge.arrow.size=.5, |
- | dev.off() | + | main=" |
+ | # dev.off() | ||
# Now let's set the vertex size by tenure. | # Now let's set the vertex size by tenure. | ||
tenure_vertex_sizes = get.vertex.attribute(krack_full," | tenure_vertex_sizes = get.vertex.attribute(krack_full," | ||
- | pdf(" | + | # pdf(" |
plot(krack_reports_to_only, | plot(krack_reports_to_only, | ||
| | ||
Line 833: | Line 845: | ||
| | ||
| | ||
- | | + | |
- | dev.off() | + | # dev.off() |
# Now let's incorporate additional tie types. We'll use the | # Now let's incorporate additional tie types. We'll use the | ||
Line 854: | Line 866: | ||
| | ||
| | ||
- | | + | |
Line 874: | Line 886: | ||
# reports-to layout but show the friendship ties: | # reports-to layout but show the friendship ties: | ||
- | pdf(" | + | # pdf(" |
plot(krack_friendship_only, | plot(krack_friendship_only, | ||
| | ||
Line 882: | Line 894: | ||
| | ||
| | ||
- | dev.off() | + | # dev.off() |
sna_eg_stanford/lab01.1576020714.txt.gz · Last modified: 2019/12/11 08:31 by hkimscil