User Tools

Site Tools


en:data_preparation_rscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
en:data_preparation_rscript [2019/02/10 20:10]
David Zelený
en:data_preparation_rscript [2019/02/10 20:26] (current)
David Zelený
Line 76: Line 76:
 dev.off () dev.off ()
 </​code>​ </​code>​
 +<code rsplus>
 +# digitalize pig
 +# library (pixmap)
 +# p <- read.pnm ('​c:​\\Users\\Zeleny\\Dropbox\\uceni\\NumEcol\\figures\\pig for transformation.ppm'​)
 +# windows ()
 +# plot.new ()
 +# plot.window (xlim = c(0, 100), ylim = c(0, 67))
 +# axis (1)
 +# axis (2)
 +# addlogo (p, c(0,100), c(0, 67))
 +# pig <- locator ()
 +# pig.df <- as.data.frame (pig)
 +# plot (pig.df)
 +# plot (pig.df, type = '​l',​ lwd = 10, log = '​xy',​ ann = T)
 +# #save (pig.df, file = '​c:​\\Users\\Zeleny\\Dropbox\\uceni\\NumEcol\\figures\\pix.df.r'​)
  
 +# load (file = '​c:​\\Users\\Zeleny\\Dropbox\\uceni\\NumEcol\\figures\\pix.df.r'​)
 +# pig.df <- pig.df/20
 +# write.table (pig.df, '​normal.pig.txt',​ sep = '​\t',​ row.names = F)
 +
 +pig.df <- read.delim ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​normal.pig.txt'​)
 +
 +exp.pics <- as.matrix (expand.grid (a = c('log (x)', '​x^(1/​3)',​ 'sqrt (x)', '​x',​ '​x^2',​ '​x^3',​ '​e^x'​),​ b = c('log (y)', '​y^(1/​3)',​ 'sqrt (y)', '​y',​ '​y^2',​ '​y^3',​ '​e^y'​)))
 +pig.df$'​log (x)' <- log (pig.df$x)
 +pig.df$'​x^(1/​3)'​ <- pig.df$x^(1/​3)
 +pig.df$'​sqrt (x)' <- sqrt (pig.df$x)
 +pig.df$'​x^2'​ <- pig.df$x^2
 +pig.df$'​x^3'​ <- pig.df$x^3
 +pig.df$'​e^x'​ <- exp (pig.df$x)
 +pig.df$'​log (y)' <- log (pig.df$y)
 +pig.df$'​y^(1/​3)'​ <- pig.df$y^(1/​3)
 +pig.df$'​sqrt (y)' <- sqrt (pig.df$y)
 +pig.df$'​y^2'​ <- pig.df$y^2
 +pig.df$'​e^y'​ <- exp (pig.df$y)
 +pig.df$'​y^3'​ <- pig.df$y^3
 +
 +right_skewed_pig <- pig.df[, c('​e^x',​ '​y'​)]
 +names (right_skewed_pig) <- c('​x',​ '​y'​)
 +write.table (right_skewed_pig,​ '​right-skewed.pig.txt',​ row.names = F, sep = '​\t'​)
 +
 +mat <- matrix (0, ncol = 8, nrow = 8)
 +mat [2:8, 2:8] <- matrix (1:49, ncol = 7, byrow = T)
 +mat [1, 2:8] <- 50:56
 +mat [2:8, 1] <- 57:63
 +
 +png ('​trans.pig.png',​ width = 8, height = 5.44, res = 300, units = '​in',​ pointsize = 4)
 +par (mar = c(2,2,2,2))
 +layout (mat, widths = c(2, rep (4, 7)), height = c(2, rep (4, 7) ))
 +#apply (as.matrix (exp.pics), 1, FUN = function (pic) plot (x = pig.df[,​pic[1]],​ y = pig.df[,​pic[2]],​ axes = F, ann = F, type = '​l',​ lwd = 5))
 +for (i in seq (1, 49))
 +{
 +  plot (x = pig.df[,​exp.pics[i,​ 1]], y = pig.df[,​exp.pics[i,​ 2]], axes = F, ann = F, type = '​l',​ lwd = 2)
 +  if (i==25)
 +  {
 +    box ()
 +    axis (1, cex.axis = 2, tick = F)
 +    axis (2, cex.axis = 2, las = 1, tick = F)
 +  }
 +}
 +
 +lapply (rev (c('​log (x)', 'sqrt (y, 3)', 'sqrt (x)', '​x',​ '​x^2',​ '​x^3',​ '​e^x'​)),​ FUN = function (x) {plot.new (); plot.window (xlim = c(0,1), ylim = c(0,1)); text (0.5,​0.5,​labels = parse (text = x), cex = 4)})
 +lapply (rev (c('​log (y)', 'sqrt (y, 3)', 'sqrt (y)', '​y',​ '​y^2',​ '​y^3',​ '​e^y'​)),​ FUN = function (x) {plot.new (); plot.window (xlim = c(0,1), ylim = c(0,1)); text (0.5,​0.5,​labels = parse (text = x), cex = 4)})
 +dev.off ()
 +</​code>​
en/data_preparation_rscript.txt · Last modified: 2019/02/10 20:26 by David Zelený