Skip to content

Instantly share code, notes, and snippets.

View gireeshkbogu's full-sized avatar

Gireesh Bogu gireeshkbogu

View GitHub Profile
library(ggplot2)
# Here I reduced the width of boxplots by 50%. because by default they look too big and ugly.
pp <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot(width = 0.5, aes(fill = factor(cyl))) + guides(fill=FALSE)
df1 <- data.frame(a = c(1, 1:3,3), b = c(39, 40, 40, 40, 39))
df2 <- data.frame(a = c(1, 1,2, 2), b = c(35, 36, 36, 35))
df3 <- data.frame(a = c(2, 2, 3, 3), b = c(24, 25, 25, 24))
@gireeshkbogu
gireeshkbogu / rugplot.r
Last active January 22, 2016 10:36
Rug plot - an laternative to show a scatter plot with densities
library(ggplot2)
x<-rnorm(300)
y<-rt(300,df=2)
xy<-data.frame(x,y)
qplot(x,y, data=xy) +
scale_x_continuous(limits=c(min(x),max(x))) +
scale_y_continuous(limits=c(min(y),max(y))) +
generate_logit_cdf <- function(mu, s,
sigma_y=0.1,
x=seq(-5,20,0.1)) {
x_ms <- (x-mu)/s
y <- 0.5 + 0.5 * tanh(x_ms)
y <- abs(y + rnorm(length(x), 0, sigma_y))
ix <- which(y>=1.0)
if(length(ix)>=1) {
y[ix] <- 1.0
}
require(ggplot2)
require(reshape2)
mtcars2 = melt(mtcars, id.vars='mpg')
ggplot(mtcars2) +
geom_jitter(aes(value,mpg, colour=variable),) + geom_smooth(aes(value,mpg, colour=variable), method=lm, se=FALSE) +
facet_wrap(~variable, scales="free_x") +
labs(x = "Percentage cover (%)", y = "Number of individuals (N)")
> meanstable
x_categories strata mu lo hi
1 Facet A Strata 1 0.020 -0.001 0.04
2 Facet A Strata 2 0.004 -0.010 0.03
3 Facet A Strata 3 0.070 0.030 0.16
4 Facet A Strata 4 0.120 0.070 0.23
5 Facet B Strata 1 -0.020 -0.030 0.01
6 Facet B Strata 2 0.040 0.020 0.07
7 Facet B Strata 3 0.040 -0.060 0.09
library (ggplot2)
# mmur <- structure(list(Medgrowth = c(-1.02232983588915, 3.01155115511551,-0.220617729642996, 1.96506550218342, 0.943970767356888, 0.810810810810807,0.0166694449074782, 0.21064457239153, 0.0876731544801004, 0.132216835610393,0.370644922164558,0.23378141437756, 1.27810650887574, 0.42301184433164,0.394880174291941, 0.54216172568924, 1.32690882134916, 0.499722376457527,-0.108885017421599), Medunemp = c(4.430550475, 2.5060469975,4.1239796475, 2.0585977455, 3.846659243, 3.1792594425, 4.0033450105,6.0882984255, 3.091889808,3.7462810695, 2.4038147815, 3.0065393475,2.3331894185, 4.9482480125, 2.0955470885, 1.616694725, 1.873037069,3.060170157, 3.0131425595), Empsize = c(324.2,270.6, 962.1,149, 962.4, 421.1, 1197.8, 777.8, 552.8, 234.8, 421.1, 203.2,915.7, 396.1, 685.9, 904.5, 1366.9, 215.4, 440.5), Eduratio = c(0.1,0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.1, 0.1, 0.3, 0.3, 0.2, 0.5, 0.2,0.3, 0.6, 0.4, 0.2, 0.1), Names = structure(c(3L, 12L, 11L, 7L,5L, 19L, 17L, 1L, 18L, 10L, 8L, 16L, 14L, 2L, 15L, 6L, 9L
library(ggplot2)
ggplot(mtcars, aes(x=wt, y=disp, colour=cyl, size=gear)) +
geom_point(shape=19, alpha=0.8)+ scale_colour_gradientn(colours=rainbow(10)) +
stat_smooth( method="lm", size=0.5, colour="black")
MYdata <- data.frame(Age = rep(c(0,1,3,6,9,12), each=20),
Richness = rnorm(120, 10000, 2500))
ggplot(data = MYdata, aes(x = Age, y = Richness)) +
geom_boxplot(aes(fill=factor(Age))) +
geom_point(aes(color = factor(Age))) +
scale_x_continuous(breaks = c(0, 1, 3, 6, 9, 12)) +
wget https://github.com/downloads/taoliu/MACS/MACS-1.4.2-1.tar.gz
tar -zxvf MACS-1.4.2-1.tar.gz
python setup.py install --prefix /users/rg/gbogu/software/MACS-1.4.2
export PYTHONPATH=/users/rg/gbogu/software/MACS-1.4.2/lib/python2.7/site-packages/:$PYTHONPATH
export PATH="/users/rg/gbogu/software/MACS-1.4.2/bin/:$PATH"
# How to plot a BIG data set (600 million rows/values with 8555 keys)
# Use the follow example!!
library(dplyr)
library(ggplot2)
data(diamonds)
# plot density of different keys
ggplot(diamonds, aes(x=depth)) + geom_line(aes(color= cut), stat="density", size=0.4, alpha=0.4)