scatter plot in R of many data 10 or more - r

hello I must do a multivariate analysis to this data
but I have to make a scatter plot of the data and I don't know that very well
This with the pairs function, if there is any way to do it and make it presentable, thank you very much.

You might give GGally::ggpairs a try. It's relatively automatic:
library(GGally)
data <- as.data.frame(matrix(rnorm(10000),ncol = 10))
data[,2] <- sample(1:6, 1000, replace = TRUE)
data[,3] <- rpois(1000,1)
data[,9] <- as.factor(sample(1:3, 1000, replace = TRUE))
ggpairs(data)

Related

Perona-Malik model in R for smoothing time series of data

Recently, i use Savitzky-Golay in signal package for smoothing my data, but it is not work well. I hear that Perona-Malik is good smooth method for this task, however, i could not realize it. My question is that is it possible realize the task to smooth the data by using P& M model by using R.
Thanks
hees
Simple example.
library(signal)
bf <- butter(5,1/3)
x <- c(rep(0,15), rep(10, 10), rep(0, 15))
###
sg <- sgolayfilt(x) # replace at here
plot(sg, type="l")
lines(filtfilt(rep(1, 5)/5,1,x), col = "red") # averaging filter
lines(filtfilt(bf,x), col = "blue") # butterworth
p

Undertanding Sample Sizes in qqplots with R

I'm trying to plot QQ graphs with the MASS Boston data set and comparing how the plots will change with increased random data points. I'm looking at the R documentation on qqnorm() but it doesn't seem to let me select an n value as a parameter? I'd like to plot the QQplots of “random” samples of size 10, 100, and 1000 samples all from a normal distribution for the same variable all in a 3x1 matrix.
Example would be if I wanted to look at the QQplot for Boston Crime, how would I get
qqnorm(Boston$crim) #find how to set n = 10
qqnorm(Boston$crim) #find how to set n = 100
qqnorm(Boston$crim) #find how to set n = 1000
Also if someone could elaborate when to use qqplot() vs qqnorm(), I'd appreciate it.
I'm inclined to believe that I should use qqplot() as such, as it does seem to give me the output I want, but I want to make sure that using rnorm(n) and then using that variable as a second argument is okay to do:
x <- rnorm(10)
y <- rnorm(100)
z <- rnorm(1000)
par(mfrow = c(1,3))
qqplot(Boston$crim, x)
qqplot(Boston$crim, y)
qqplot(Boston$crim, z)
The question is not clear but to plot samples of a vector, define a vector N of sample sizes and loop through it. The lapply loop will sample from the vector, plot with the Q-Q line and return the qqnorm plot.
data(Boston, package = "MASS")
set.seed(2021)
N <- c(10, 100, nrow(Boston))
qq_list <- lapply(N, function(n){
subtitle <- paste("Sample size:", n)
i <- sample(nrow(Boston), n, replace = FALSE)
qq <- qqnorm(Boston$crim[i], sub = subtitle)
qqline(Boston$crim[i])
qq
})

barplot graph is not working (beside = T)

I want to draw a graph of the mean by a value.
It's a statistic graph, and for this I made a list of each grade.
It used the "list" function to bring in each score and the average of each value using the "lapply" function.
But I tried to use it as a 'barlpot','beside =T' but the graph was not made properly.
I don't know if the graph format is wrong or what kind of mistake I made.
Code
list01 <-list(Sci=df_01$Sci,Eng = df_01$Eng,Math = df_01$Math)
C01_gd = lapply(list01,mean)
as.matrix(C01_gd)
barplot(as.matrix(C01_gd) ,border="white",beside = T)
Here's a tentative solution (tentative, as you have not provided a sample of your data).
Some reproducible data for illustration:
set.seed(12)
df <- data.frame(
Sci = sample(1:6, 100, replace = T),
Eng = sample(1:6, 100, replace = T),
Math = sample(1:6, 100, replace = T)
)
The calculation of the means could not be simpler using apply:
means <- apply(df, 2, mean)
And drawing the barplot is not rocket science either:
barplot(means)

Most efficient way of drawing a heatmap from matrix with OpenGL?

Assume a matrix m of integer values:
m <- matrix(sample(1:10, 100, replace = TRUE), nrow = 10)
Given a colour palette that maps those values from 1 to 10 to some colours, how to show matrix m as a heatmap in R with OpenGL graphics, e.g. using the rgl package? (Preferably in the most efficient way.)
The very thorough answer here suggests this may not be what you want; you might want to try the solution below against the other solutions benchmarked there. Nonetheless:
Set up data and colour map
set.seed(101)
library(viridisLite)
vv <- viridis(10)
m <- matrix(sample(1:10, 100, replace = TRUE), nrow = 10)
Draw the picture:
library(rgl)
view3d(theta=0, phi=0) ## head-on view
par3d(zoom=0.7) ## (almost) fill window
surface3d(x = 1:10, y = 1:10, z = matrix(0, 10,10),
color = vv[m],
smooth=FALSE, lit=FALSE ## turn off smoothing/lights
)
You may need to use pop3d() between surfaces to clear the previous surface ...

Making a 3D surface from time series data in R

I have a large data set which I would like to make a 3D surface from. I would like the x-axis to be the date, the y-axis to be the time (24h) and the z-axis (height) to be a value I have ($). I am a beginner with R, so the simpler the better!
http://www.quantmod.com/examples/chartSeries3d/ has a nice example, but the code is way to complicated for my skill level!
Any help would be much appreciated - anything I have researched so far needs to have the data sorted, which is not suitable I think.
Several options present themselves, persp() and wireframe(), the latter in package lattice.
First some dummy data:
set.seed(3)
dat <- data.frame(Dates = rep(seq(Sys.Date(), Sys.Date() + 9, by = 1),
each = 24),
Times = rep(0:23, times = 10),
Value = rep(c(0:12,11:1), times = 10) + rnorm(240))
persp() needs the data as the x and y grid locations and a matrix z of observations.
new.dates <- with(dat, sort(unique(Dates)))
new.times <- with(dat, sort(unique(Times)))
new.values <- with(dat, matrix(Value, nrow = 10, ncol = 24, byrow = TRUE))
and can be plotted using:
persp(new.dates, new.times, new.values, ticktype = "detailed", r = 10,
theta = 35, scale = FALSE)
The facets can be coloured using the col argument. You could do a lot worse than study the code for chartSeries3d0() at the page you linked to. Most of the code is just drawing proper axes as neither persp() nor wireframe() handle Date objects easily.
As for wireframe(), we
require(lattice)
wireframe(Value ~ as.numeric(Dates) + Times, data = dat, drape = TRUE)
You'll need to do a bit or work to sort out the axis labelling as wireframe() doesn't work with objects of class "Date" at the moment (hence the cast as numeric).

Resources