Skip to content

Instantly share code, notes, and snippets.

@valentinitnelav
Last active November 23, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valentinitnelav/3b2a572ab5576cad29a64ab5d929d415 to your computer and use it in GitHub Desktop.
Save valentinitnelav/3b2a572ab5576cad29a64ab5d929d415 to your computer and use it in GitHub Desktop.
setwd("share/")
getwd()
my_data <- read.table("data/drunkwalks_data.txt", header = TRUE)
plot(my_data)
aggreg <- table(my_data$SEX, my_data$DOMINANT_SIDE)
rownames(aggreg) <- c("female", "male")
colnames(aggreg) <- c("left-handed", "right-handed")
pdf(file = "test.pdf",
width = 9/2.54, height = 7/2.54,
family="Times", pointsize = 8)
# Adjust margins of plotting region (Bottom, Left, Top, Right) : X[cm]/2.54 = inch
par(mai = c(0.9/2.54, 1.4/2.54, 0.15/2.54, 2/2.54))
barplot(aggreg,
beside = TRUE,
ylim = c(0, 60),
ylab = "Counts",
legend.text = c("female", "male"),
args.legend = list(x = 8,
y = 50,
text.font = 3,
xpd = TRUE))
# legend("topright", inset = c(-0.2,0), legend = c("female", "male"))
dev.off()
aggreg2 <- table(my_data$MATCH, my_data$DOMINANT_SIDE)
colnames(aggreg2) <- c("left-handed", "right-handed")
rownames(aggreg2) <- c("stumbling left", "stumbling right")
aggreg2
pdf(file = "test2.pdf",
width = 9/2.54, height = 7/2.54,
family="Times", pointsize = 8)
# Adjust margins of plotting region (Bottom, Left, Top, Right) : X[cm]/2.54 = inch
par(mai = c(0.9/2.54, 1.4/2.54, 0.15/2.54, 2.7/2.54))
barplot(aggreg2,
beside = TRUE,
ylim = c(0, 60),
ylab = "Counts",
legend.text = c("left-handed", "right-handed"),
args.legend = list(x = 9,
y = 50,
text.font = 3,
xpd = TRUE))
dev.off()
##########
pdf(file = "test4.pdf",
width = 15/2.54, height = 7/2.54,
family="Times", pointsize = 8)
# layout(matrix(1:2, ncol=2))
par(mai = c(0.9/2.54, 1.4/2.54, 2/2.54, .5/2.54),
mfrow = c(1,2))
barplot(aggreg,
beside = TRUE,
ylim = c(0, 60),
ylab = "Counts",
legend.text = c("female", "male"),
args.legend = list(x = 6,
y = 70,
text.font = 3,
xpd = TRUE))
# par(mai = c(0.9/2.54, 1.4/2.54, 0.15/2.54, 2.5/2.54))
barplot(aggreg2,
beside = TRUE,
ylim = c(0, 60),
# ylab = "Counts",
legend.text = c("stumbling left", "stumbling right"),
args.legend = list(x = 6,
y = 70,
text.font = 3,
xpd = TRUE))
mtext("Karl Pearson's drunkard's walk", side = 3, line = 4, at = -0.5, font=2, cex=14/8)
dev.off()
#############
# ggplot(data = my_data,
# aes(x = DOMINANT_SIDE)) +
# geom_bar(stat="identity",
# position=position_dodge())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment