Articles

Affichage des articles du mars, 2020

Empty category in box plot

Image
df <- data.frame(length=1:100,                  year=c(rep(1980, 20), rep(1981, 20), rep(1983, 20), rep(1984, 20), rep(1985, 20))) boxplot(length ~ year, df) # Not good ! df$year <- factor(df$year,  levels = 1980:1985) boxplot(length ~ year, df)

Install xml2 package in MacOSX

In terminal: brew install libxml2 wget https://cran.r-project.org/src/contrib/xml2_1.2.5.tar.gz (check the latest version here:  https://cran.r-project.org/web/packages/xml2/index.html ) R CMD INSTALL --configure-vars='INCLUDE_DIR=/usr/local/opt/libxml2/include/libxml2 LIB_DIR=/usr/local/opt/libxml2/lib/' ./xml2_1.2.5.tar.gz

Update nloptr package to 1.2.2 version

To update the  nloptr  package, you need do first: brew install nlopt in terminal

Manipulate image with imager

library(imager) # Ici l'image est en couleur car chaque pixel a 3 valeurs: Red Green Blue (RGB) a <- array(data = runif(10*10*1*3), dim=c(10, 10, 1, 3)) class(a) <- c("cimg", "imager_array", "numeric") plot(a) print.default(a) # Ici l'image est en niveau de gris car on met la même valeur pour RGB a <- array(data = rep(runif(10*10*1), 3), dim=c(10, 10, 1, 3)) class(a) <- c("cimg", "imager_array", "numeric") plot(a) print.default(a) # I add a red point a[5, 5, 1, 1:3] <- c(1, 0, 0) plot(a, interpolate = FALSE) # Ici je ne garde qu'une valeur au lieu de 3 pour RGB; c'est donc du niveau de gris a <- a[, , , 1, drop=FALSE] plot(a) print.default(a) # là je seuille les valeurs a[, , 1, 1] <- ifelse(a[, , 1, 1]<0.5, 0, 1) plot(a) print.default(a)