This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bubble plot - takes in a dataframe with five different properties, for X, Y, Size, ColorA, B and C, plus additional parameters to control appearances of the plots produced | |
bubbles_in_2colors<-function( dataset, to_jitter=F, prop_names=NULL, titles=list(main='X vs Y', color='colors', size='size'), min_size = 1, max_size = 5, max_sat = 200, fav_col='green', alpha_default=0.7, ...) { | |
# NB: this code can handle a third primary color, but human eyes can't so for the moment I've forbidden that option. | |
if(exists('dataset')) { | |
if (is.null(prop_names)) {print(prop_names<-names(dataset))}; | |
if (length(prop_names) ==4) {propX<-dataset[,1]; propY<-dataset[,2]; propS<-dataset[,3]; propCA<-dataset[,4]} | |
else if (length(prop_names) ==5) {propX<-dataset[,1]; propY<-dataset[,2]; propS<-dataset[,3]; propCA<-dataset[,4]; propCB<-dataset[,5]} | |
else if (length(prop_names) ==6) {propX<-dataset[,1]; propY<-dataset[,2]; propS<-dataset[,3]; propCA<-dataset[,4]; propCB<-dataset[,5]; propCC<-dataset[,6]; print("Three colors a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2); | |
library(grid); | |
data(iris) | |
x <- jitter(iris[,c('Sepal.Length')]) | |
y <- jitter(iris[,c('Sepal.Width')]) | |
z <- factor(iris[,c('Species')]) | |
# The color blind palette without black: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My take on multi-variable pie charts. Inspired by: | |
# http://learnr.wordpress.com/2010/08/16/consultants-chart-in-ggplot2/ | |
require(ggplot2) | |
require(reshape) | |
# let's create a dummy set | |
nvars<-3; varnames <- letters[1:nvars] # the number and names of the variables | |
ncpd<-16; cpdnames <- toupper(letters[1:ncpd]) # the number and name of item (in my case compounds)# a matrix filled with pseudorandom gibberish | |
MyMatrx<-matrix(ncol=nvars,nrow=ncpd,data=sample(5, repl=T, size=ncpd*nvars)) | |
rownames(MyMatrx)<-cpdnames; colnames(MyMatrx)<-varnames | |
# alternatively, one could read such a data structure from a file... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generic routine to plot bubbles in different colors and sizes - run me using | |
# source(file.path(Sys.getenv("USERPROFILE"),"Documents/My Dropbox/Proj01_p100PassiveTransport/Data/Models/Plot_Bubbles_in_2_Colors.r")) | |
# if (exists('debug_flag') & debug_flag) {# cleans up everything but the debug_flag | |
# rm(list=ls(all=TRUE)[-which(ls()=='debug_flag')]) | |
# } else {debug_flag<-F} # default for debug_flag is obviously FALSE | |
rm('File_In','Calc'); # initial cleanup - so that we read data from scratch | |
source(file.path(Sys.getenv("USERPROFILE"),"Documents/My Dropbox/Software/useful.r")) | |
# set up home directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(ggplot2) | |
require(reshape) | |
# windows() | |
getRandString<-function(len=12) return(paste(sample(c(LETTERS,letters),len,replace=TRUE),collapse='')) | |
cpd_name_len<-8 | |
descr_name_len<-3 | |
# let's create a dummy set | |
nvars<-4; varnames <- as.character(lapply(X=rep(descr_name_len,times=nvars), FUN=getRandString)) # the number and names of the variables | |
ncpd<-25; cpd_x_row<-5; rows_x_page<-6; cpd_x_page<-cpd_x_row*rows_x_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(deSolve) # require this library | |
Lorenz<-function(t, state, parameters) { | |
with(as.list(c(state, parameters)),{ | |
# rate of change | |
dX <- a*X + Y*Z | |
dY <- b * (Y-Z) | |
dZ <- -X*Y + c*Y - Z | |
# return the rate of change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
pXY<-ggplot(as.data.frame(out)) +geom_path(aes(X, Y, col=time, alpha=Z)) + opts(legend.position = "none") | |
pZY<-ggplot(as.data.frame(out)) +geom_path(aes(Z, Y, col=time, alpha=X)) + opts(legend.position = "none") | |
pXZ<-ggplot(as.data.frame(out)) +geom_path(aes(X, Z, col=time, alpha=Y)) + opts(legend.position = c(1.1,0.5)) | |
p3D<-ggplot(as.data.frame(out)) +theme_invisible() +geom_path(aes(X*Y, X*Z, col=time, alpha=Y*Z)) + scale_alpha(range = c(0.4, 0.8)) + opts(legend.position = 'none') | |
multiplot(pXY,pZY,pXZ,p3D, cols=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source("C:/Users/Luca/Documents/My Dropbox/Software/gWidgets.r") | |
rm(list=ls(all=TRUE)) | |
library(ggplot2) | |
library(gWidgets) | |
options("guiToolkit"="RGtk2") | |
library(deSolve) | |
# from: http://wiki.stdout.org/rcookbook/Graphs/Multiple%20graphs%20on%20one%20page%20(ggplot2)/ | |
multiplot <- function(..., plotlist=NULL, cols) { | |
require(grid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source("C:/Users/LucaF/Documents/My Dropbox/Software/R/Exoplanets.r") | |
rm(list=ls(all=TRUE)) | |
if (!exists('palette_l')) {palette_l<-50} # how many steps in the palette | |
N<-650 # number of exoplanets | |
R<-1000 # radius of a 2D-circle where you'll want to plot them | |
MinMass<-5; # minimum mass for the planets | |
MaxMass<-100; # maximum mass for the planets | |
P<-6 # power exponent for the mass distribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(deSolve) # require this library | |
solveLorenz <- function(pars, times=seq(0,100,by=0.1)) { | |
derivs <- function(t, state, pars) { # returns rate of change | |
with(as.list(c(state, pars)), { | |
dX <- a*X + Y*Z | |
dY <- b * (Y-Z) | |
dZ <- -X*Y + c*Y - Z | |
return(list(c(dX, dY, dZ))) | |
} |
OlderNewer