Bastão de Asclépio & Símbolo de Integral
invisible(Sys.setlocale("LC_CTYPE", "pt_BR.UTF-8"))
invisible(Sys.setlocale("LC_ALL","pt_BR.UTF-8"))
options(warn=-1)
suppressMessages(library(car, warn.conflicts=FALSE))
suppressMessages(library(colorspace, warn.conflicts=FALSE))
suppressMessages(library(DescTools, warn.conflicts=FALSE))
suppressMessages(library(dichromat, warn.conflicts=FALSE))
suppressMessages(library(dplyr, warn.conflicts=FALSE))
suppressMessages(library(HistData, warn.conflicts=FALSE))
suppressMessages(library(knitr, warn.conflicts=FALSE))
suppressMessages(library(labelled, warn.conflicts=FALSE))
suppressMessages(library(latex2exp, warn.conflicts=FALSE))
suppressMessages(library(MASS, warn.conflicts=FALSE))
suppressMessages(library(plot3D, warn.conflicts=FALSE))
suppressMessages(library(plotly, warn.conflicts=FALSE))
suppressMessages(library(rayshader, warn.conflicts=FALSE))
suppressMessages(library(RColorBrewer, warn.conflicts=FALSE))
suppressMessages(library(readxl, warn.conflicts=FALSE))
suppressMessages(library(reshape2, warn.conflicts=FALSE))
suppressMessages(library(rgl, warn.conflicts=FALSE))
suppressMessages(library(scatterplot3d, warn.conflicts=FALSE))
suppressMessages(library(shinyjs, warn.conflicts=FALSE))
# https://www.r-bloggers.com/2021/03/regplane3d-plotting-3d-regression-predictions-in-r/
## devtools
if(!("devtools" %in% installed.packages()))
install.packages("devtools")
library(devtools)
Carregando pacotes exigidos: usethis
## regplane3D
if(!("regplane3D" %in% installed.packages()))
devtools::install_github("denis-cohen/regplane3D")
library(regplane3D)
Desmos Geometry: https://www.desmos.com/geometry?lang=pt-BR
Desmos 2D Modo Complexo e Modo Polar: https://www.desmos.com/calculator?lang=pt-BR
grid()
gains optional argument
nintLog
invisible(Sys.setlocale("LC_CTYPE", "pt_BR.UTF-8"))
invisible(Sys.setlocale("LC_ALL","pt_BR.UTF-8"))
# mesmo cálculo anterior
a_vals <- seq(0.6, 3.1, length.out = 30)
r_vals <- seq(0, 2.2, length.out = 30)
grid <- expand.grid(a = a_vals, r = r_vals)
r_0 <- 2.2
S_vals <- matrix(grid$a * grid$r^2 * (r_0 - grid$r),
nrow = length(a_vals),
ncol = length(r_vals),
byrow = FALSE)
# gráfico interativo
rgl::persp3d(x = a_vals, z = r_vals, y = S_vals,
col = "orangered",
main = latex2exp::TeX(sprintf(r'($r_0=%.2f$)',r_0)),
xlab = "a",
zlab = "r",
ylab = "S"
)
rgl::view3d(theta = 45, phi = 10, zoom=0.9)
rgl::rglwidget()
RPubs
Curvas francesas
4. Método gráfico (Capítulo 7)
O olho humano é muito rápido em reconhecer padrões e formas.
As informações contidas nas relações matemáticas geralmente podem ser apresentadas em forma gráfica para melhor compreensão.
A menos que seja necessária uma alta precisão, a representação gráfica, como diagramas e nomogramas, pode substituir longas tabelas de funções. Às vezes, até cálculos numéricos tediosos podem ser evitados com o emprego de ferramentas gráficas.
Já estamos familiarizados com gráficos retangulares e polares. Eles são vantajosos porque mostram claramente os intervalos onde uma função é crescente ou decrescente, onde máximos e mínimos estão localizados etc.
Mas também há desvantagens. Às vezes falta espaço apropriado para o alcance de uma função. Ou a relação de mais de duas variáveis deve ser apresentada no plano. Nesses casos, as escalas não lineares ajudam consideravelmente.
Fig. 7.2. Uma escala logarítmica na base 10 versus uma escala linear
[1] 0.30103
[1] 0.30103
[1] 2
Foi inventada pelo matemático inglês William Oughtred, em 1622, baseando-se na tábua de logaritmos que fora criada por John Napier pouco antes, em 1614.
A régua de cálculo é um dispositivo de cálculo que se baseia na sobreposição de escalas logarítmicas. Os cálculos são realizados por meio de uma técnica mecânica analógica que permite a elaboração dos cálculos por meio de guias deslizantes graduadas, ou seja, réguas logarítmicas que deslizam umas sobre as outras, e os valores mostrados em suas escalas são relacionados através da ligação por um cursor dotado de linhas estrategicamente dispostas, que têm a função de correlacionar as diversas escalas da régua de cálculo.
Agora ilustramos o uso de uma escala logarítmica no caso em que uma variável abrange uma ampla faixa. Uma apresentação linear seria virtualmente impossível. A taxa de mortalidade medida em incidência por 100.000 habitantes varia entre cerca de 1 e 104 em função da idade (Fig. 7.5).
Fig. 7.5. Gráfico semilogarítmico da taxa de mortalidade dependente da idade para 100.000 pessoas nos Estados Unidos por volta de 1960.
Obs.: CNS vascular refere-se às alterações vasculares do sistema nervoso central (SNC), ou seja, condições que afetam os vasos sanguíneos do cérebro e da medula espinhal.
Para ilustrar tal transformação, consideramos um método de determinação do volume de plasma sanguíneo em um corpo humano ou animal. Uma quantidade conhecida de tiossulfato é injetada na corrente sanguínea. Se o tiossulfato se misturasse homogeneamente com o plasma sanguíneo sem qualquer perda para outras partes do corpo, seria fácil calcular o volume de sangue a partir da concentração de tiossulfato no plasma.
Em vez disso, a substância é continuamente excretada pelos rins, enquanto a mistura do tiossulfato com o plasma dificilmente se completa antes de decorridos 10 minutos. Para lidar com este problema, várias medições da concentração de tiossulfato são feitas e um método gráfico é aplicado para extrapolar retroativamente. Seguindo Randall (1958 ou 1962, p. 67), consideramos um experimento: Em um animal, 0.5 g de tiossulfato foi injetado. Dez minutos após a injeção e em intervalos sucessivos de 10 minutos, foram obtidas as seguintes concentrações plasmáticas de tiossulfato: 44 38 33 28 25 mg/100 ml.
Fig. 7.6. Gráfico semilogarítmico da concentração plasmática após a injeção de 0.5 g de tiossulfato.
Como de costume, a excreção pelo rim leva a uma diminuição exponencial da concentração. Portanto, plotamos os dados em um sistema de coordenadas semilogarítmicas (Fig. 7.6). Os pontos estão em uma linha reta com considerável precisão. Estamos interessados na concentração como era antes do rim começar a excretar tiossulfato.
Portanto, extrapolamos os dados retroativamente para obter a concentração plasmática no momento da injeção. Assim, obtemos aproximadamente 50 mg/100 ml.
Seja V o volume plasmático total do animal. Então
\[ V= \dfrac{0.5 \;\text{g}}{\dfrac{50 \;\text{mg}}{100 \;\text{ml}}}= 1000 \;\text{ml} \]
x <- seq(10,50,10)
y <- c(44, 38, 33, 28, 25)
plot(x, y,
xlab="Time after Injection (min)",
ylab="Plasma Concentration (mg/100 ml)",
xlim=c(0,60),
ylim=c(20,60))
plot(x, y,
xlab="Time after Injection (min)",
ylab="log Plasma Concentration (mg/100 ml)",
xlim=c(0,60),
ylim=c(20,60),
log="y")
plot(x, log(y),
xlab="Time after Injection (min)",
ylab="log Plasma Concentration (mg/100 ml)",
xlim=c(0,60),
ylim=c(3,4.25))
fit <- lm(log(y)~x)
summary(fit)
Call:
lm(formula = log(y) ~ x)
Residuals:
1 2 3 4 5
0.0031150 0.0001125 0.0026348 -0.0180673 0.0122049
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.924676 0.013432 292.19 8.84e-08 ***
x -0.014360 0.000405 -35.46 4.93e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.01281 on 3 degrees of freedom
Multiple R-squared: 0.9976, Adjusted R-squared: 0.9968
F-statistic: 1257 on 1 and 3 DF, p-value: 4.933e-05
origem <- data.frame(x=0)
V <- 0.5*100/(exp(predict(fit, origem)[[1]])*1e-3)
cat("V =", round(V,2), "ml")
V = 987.43 ml
Quando ambos os eixos de um sistema de coordenadas têm escalas logarítmicas, ele é chamado de logarítmico duplo. O termo gráfico log-log também é usado.
\[ X = \log(x), \; \; Y = \log(y) \]
Então a Fig. 7.7 ilustra três formas de apresentação:
Fig. 7.7. Três apresentações de um sistema de coordenadas logarítmicas duplas.
Como primeira aplicação biológica, estudamos a relação entre o comprimento e a massa de Heterodon nasicus (cobra hognose ocidental). Suponha que todas as cobras desta espécie, sejam jovens ou velhas, tenham a mesma forma. Então, sua massa W deve ser proporcional ao cubo de seu comprimento L, i.e.,
\[ W=aL^{3} \]
com uma certa constante a. Aplicando logaritmo obtemos
\[ \log(W) = \log(a) + 3\log(L) \]
Esta é uma relação linear entre \(\log(L)\) e \(\log(W)\). Portanto, um gráfico logarítmico duplo é uma linha reta com inclinação 3. As medições reais mostram que os pontos que representam cobras individuais se desviam ligeiramente de uma linha reta (ver Fig. 7.8).
Fig. 7.8. Linhas de regressão de massa total versus comprimento ajustadas a uma amostra de 158 machos e 167 fêmeas de cobras hognose ocidentais (Heterodon nasicus) de Harvey County, Kansas. Os machos são representados por círculos preenchidos e as fêmeas por círculos abertos. Os círculos pequenos representam um único registro e os símbolos maiores representam de dois a quatro registros. Tanto a abscissa quanto a ordenada estão em escala logarítmica.
Obs.: Snout-Vent Length (SVL): distância do focinho (snout) até a abertura da cloaca (vent).
Bertalanffy (1957) é uma das mais importantes referências sobre este assunto.
Traçamos a produção diária média de calor (cal/dia) de animais de sangue quente em relação à massa corporal média (kg) (Fig. 7.9). Se forem usadas escalas logarítmicas para ambas as quantidades, os pontos estarão muito próximos de uma linha reta.
Isso indica que a relação pode ser bem aproximada por uma função de potência.
Fig. 7.9. A produção diária de calor de animais de sangue quente plotados contra a massa corporal em escalas logarítmicas.
A produção diária de calor nos animais de sangue quente (endotérmicos) está diretamente relacionada à taxa metabólica. A taxa metabólica representa a quantidade de energia que o corpo gasta para realizar processos vitais, e esta energia é principalmente liberada como calor. Nos animais endotérmicos, a taxa metabólica é influenciada por fatores como:
Tamanho Corporal: Em geral, animais menores têm uma taxa metabólica por unidade de massa mais alta, pois precisam gerar mais calor para manter sua temperatura corporal.
Atividade Física: O nível de atividade afeta significativamente a taxa metabólica. Exercício e movimentação aumentam a produção de calor.
Temperatura Ambiente: Para manter a homeostase térmica, animais endotérmicos aumentam sua taxa metabólica em ambientes frios para gerar mais calor, enquanto reduzem em ambientes quentes.
Dieta e Digestão: O processo de digestão também aumenta a produção de calor, chamado de efeito térmico dos alimentos.
Assim, a produção diária de calor reflete a taxa metabólica basal (energia necessária para manter funções vitais básicas em repouso) mais a energia utilizada para atividade física e outros processos, como digestão.
Conforme COMAP, 2003, p. 653-6,
\[ M\propto V \propto L^3 \]
Então:
\[ M^{1/3}\propto V^{1/3}\propto L \]
ou
\[ L\propto M^{1/3} \]
Supondo que a taxa metabólica, B, é proporcional à área da superfície do corpo, S, então:
\[ B\propto S\propto L^2\propto \left(M^{1/3}\right)^2=M^{2/3} \]
Espera-se que a taxa metabólica seja proporcional à potência \(2/3\) da massa corporal, \(B\propto M^{2/3}\).
Conforme Savage et al. (2007) e West et al. (2001), em mamíferos, pássaros, peixes, moluscos e plantas, a taxa metabólica \(B\) (W = J/s) é proporcional \(M^{3/4}\):
\[ \begin{align} B &\propto M^{3/4} \\ &\propto V^{3/4} \\ B &\propto S^{9/8} \end{align} \]
Portanto, a taxa metabólica. \(B\), aumenta inelasticamente com o aumento do volume, \(\eta(V)=3/4=0.75\%\), e elasticamente com o aumento da superfície, \(\eta(S)=9/8=1.125\%\).
O Índice de Massa Corporal (IMC), também conhecido como Quociente de Quetelet, foi desenvolvido em 1832 pelo matemático e estatístico belga Adolphe Quetelet. A história e desenvolvimento do IMC são interessantes e refletem a evolução da compreensão da relação entre massa corporal total (MCT) e saúde.
O Índice de Massa Corporal (IMC) é uma medida usada para avaliar se uma pessoa está com um MCT saudável em relação à sua estatura.
Ele é calculado dividindo-se MCT da pessoa em quilograma (kg) pelo quadrado de sua estatura em metro (m2). A fórmula é a seguinte:
\[ \text{IMC} = \dfrac{\text{MCT (kg)}}{\text{estatura (m)}^2} \]
Exemplo:
Se uma pessoa adulta tem 70 kg e 1.75 m de estatura, o IMC é calculado como:
\[ \text{IMC} = \dfrac{70}{1.75^2} = 22.9 \]
Portanto, essa pessoa está na categoria de MCT normal.
Categorias de IMC:
Segundo a Organização Mundial da Saúde (OMS), as categorias de IMC são:
BMI and BSA (Du Bois): Calculate by QxMD
“Se o homem aumentasse igualmente em todas as dimensões, seu peso em diferentes idades seria proporcional ao cubo de sua altura. No entanto, isso não é o que realmente observamos. O aumento de peso é mais lento, exceto durante o primeiro ano após o nascimento; então, a proporção que acabamos de mencionar é observada de maneira bastante regular. Mas, após esse período, e até próximo à idade da puberdade, o peso aumenta quase como o quadrado da altura. O desenvolvimento do peso volta a ser muito rápido na puberdade e quase para após os vinte e cinco anos. Em geral, não erramos muito ao supor que, durante o desenvolvimento, os quadrados do peso em diferentes idades são proporcionais às quintas potências da altura; o que naturalmente leva à conclusão, ao manter a densidade específica constante, de que o crescimento transversal do homem é menor do que o vertical.”
Quetelet (1842), apud Eknoyan, 2008, p. 49
Para uma função exponencial, aplicamos semilogarítmica, mas para uma função potência, um gráfico logarítmico duplo.
Em cada caso, o gráfico da função é uma linha reta.
invisible(Sys.setlocale("LC_CTYPE", "pt_BR.UTF-8"))
invisible(Sys.setlocale("LC_ALL","pt_BR.UTF-8"))
# exponencial
curve(2^(-x), 1, 20,
main = expression("Função exponencial: " ~ y == 2^{-x}),
xlab = "x", ylab = "y")
curve(2^(-x),1,20,
main=expression("Função exponencial: " ~ y == 2^{-x}),
xlab="x", ylab="log(y)",
log="y")
x <- 1:20
y <- 2^(-x)
DescTools::PlotLog(y ~ x, log = "y",
main=expression("Função exponencial: " ~ y == 2^{-x}))
curve(x^2,1,20,
main=expression("Função potência: " ~ y == x^{2}),
xlab="log(x)", ylab="log(y)",
log="xy")
# Average brain and body weights for 28 species of land animals.
Dados <- MASS::Animals
print(summary(Dados))
body brain
Min. : 0.023 Min. : 0.40
1st Qu.: 3.100 1st Qu.: 22.23
Median : 53.830 Median : 137.00
Mean : 4278.439 Mean : 574.52
3rd Qu.: 479.000 3rd Qu.: 420.00
Max. :87000.000 Max. :5712.00
body brain
Mountain beaver 1.350 8.1
Cow 465.000 423.0
Grey wolf 36.330 119.5
Goat 27.660 115.0
Guinea pig 1.040 5.5
Dipliodocus 11700.000 50.0
Asian elephant 2547.000 4603.0
Donkey 187.100 419.0
Horse 521.000 655.0
Potar monkey 10.000 115.0
Cat 3.300 25.6
Giraffe 529.000 680.0
Gorilla 207.000 406.0
Human 62.000 1320.0
African elephant 6654.000 5712.0
Triceratops 9400.000 70.0
Rhesus monkey 6.800 179.0
Kangaroo 35.000 56.0
Golden hamster 0.120 1.0
Mouse 0.023 0.4
Rabbit 2.500 12.1
Sheep 55.500 175.0
Jaguar 100.000 157.0
Chimpanzee 52.160 440.0
Rat 0.280 1.9
Brachiosaurus 87000.000 154.5
Mole 0.122 3.0
Pig 192.000 180.0
a b Std. Error a Std. Error b t value a t value b
Linear 576.37 -4.33e-04 265.912 1.59e-02 2.17 -0.0272
Power 12.87 4.96e-01 0.179 7.82e-02 6.18 6.3451
Exponential 79.36 1.20e-05 0.476 2.85e-05 9.18 0.4227
Logistic 3.94 -1.36e-05 0.637 3.81e-05 6.18 -0.3583
Pr(>|t|) a Pr(>|t|) b R squared Adj. R squared F value Pr(>F)
Linear 3.95e-02 9.78e-01 2.85e-05 -0.0384 7.42e-04 9.78e-01
Power 1.53e-06 1.02e-06 6.08e-01 0.5925 4.03e+01 1.02e-06
Exponential 1.21e-09 6.76e-01 6.83e-03 -0.0314 1.79e-01 6.76e-01
Logistic 1.54e-06 7.23e-01 4.91e-03 -0.0334 1.28e-01 7.23e-01
DescTools::PlotLog(brain ~ body,
data=Dados,
log="xy",
xlab="Body (kg)",
ylab="Brain (g)",
xlim=c(.01, 1e5),
ylim=c(.1, 1e4),
main="Animal brain vs body size",
pch=21,
bg="grey",
cex=1.5)
Começamos esta seção com uma proposição geométrica: seja P um ponto em um triângulo equilátero. Então a soma das distâncias de P dos três lados é igual à altura do triângulo. Em outras palavras: a soma das distâncias permanece constante quando movemos o ponto P de qualquer posição para qualquer outra posição dentro do triângulo.
Fig. 7.10. A soma das três distâncias h1, h2 e h3 de um ponto P dos lados de um triângulo equilátero é igual a h, a altura do triângulo.
A Fig. 7.11 mostra como esse gráfico é construído. As três variáveis podem ser a concentração de três componentes A, B, C de uma substância. Eles somam 100%.
Fig. 7.11. Gráfico trilinear para traçar concentrações variáveis de três componentes de uma substância.
Nos tentáculos de Hydra attenuata Pall. (pólipo de água doce) existem três tipos de nematocistos (células filamentosas): os estenotelos relativamente grandes, os isorhizas e os desmonemes, ambos um pouco menores. Todos os três tipos foram contados nos cinco tentáculos de indivíduos do sexo feminino. Os resultados são:
Como temos três componentes, é bastante conveniente plotar as porcentagens em um gráfico trilinear (Fig. 7.12).
Fig. 7.12. Distribuição de nematocistos nos cinco tentáculos de um indivíduo fêmea Hydra atenua Pall.
Aplicações interessantes de gráficos trilineares também são conhecidas na genética.
Fig. 7.13. As porcentagens dos genótipos AA, Aa, aa plotadas em um gráfico trilinear. Populações panmíticas são representadas por pontos caindo em uma parábola.
Sejam A e a dois genes no mesmo locus. Os indivíduos são então homozigotos AA, aa ou heterozigotos Aa. Sejam pAA, paa, pAa as porcentagens dos três genótipos em uma população.
Então, por definição
\[ p_{AA}+p_{aa}+p_{Aa}=100\% \]
Cada população é representada por um ponto em um gráfico trilinear cuja altura é 100% e cujas coordenadas são pAA, paa, pAa Sob a hipótese de panmixia (acasalamento aleatório) a lei de Hardy-Weinberg afirma que
\[ p_{Aa}^{2}=4p_{AA}p_{aa} \]
Pode-se mostrar que as populações que satisfazem esta última equação são representadas por pontos localizados em uma parábola (Fig. 7.13).
O equilíbrio de Hardy-Weinberg (também princípio de Hardy-Weinberg, ou lei de Hardy-Weinberg) é a base da genética de populações. Foi demonstrado independentemente por Godfrey Harold Hardy na Inglaterra e por Wilhelm Weinberg, na Alemanha, em 1908. Afirma que, em uma população mendeliana, dentro de determinadas condições, as frequências alélicas permanecerão constantes ao passar das gerações. Independentemente de um gene ser raro ou frequente, sua frequência permanecerá a mesma com relação aos outros desde que essas condições sejam mantidas. Por pura intuição poder-se-ia supor que alelos raros se tornariam cada vez mais raros e que alelos frequentes aumentassem cada vez mais sua frequência, simplesmente por já serem raros ou comuns, mas o princípio de Hardy-Weinberg demonstra matematicamente que isso não ocorre. (https://pt.wikipedia.org/wiki/Equil%C3%ADbrio_de_Hardy-Weinberg)
plot
do Rpracma::plotyy
: Two-ordinates Plotx <- seq(0, 20, by = 0.01)
y1 <- 200*exp(-0.05*x)*sin(x)
y2 <- 0.8*exp(-0.5*x)*sin(10*x)
pracma::plotyy(x, y1, x, y2, main = "Two-ordinates Plot")
legend("topright",
legend = c(
expression(y[1] == 200 * e^{-0.05 * x} * sin(x)),
expression(y[2] == 0.8 * e^{-0.5 * x} * sin(10 * x))
),
col = c("black", "blue"),
lty = 1,
bty = "n")
É muito comum a necessidade de exibir expressões matemáticas no
título dos gráficos. Para isso, você pode usar a função
expression
. Você pode procurar todas as opções disponíveis
para usar a notação matemática do tipo \(\LaTeX\) chamando
?plotmath
.
No entanto, a sintaxe da função é bem diferente da sintaxe do \(\LaTeX\). Se preferir, você pode usar a
função \(\TeX\) do pacote
latex2exp
. No entanto, observe que esta função converte a
notação \(\TeX\) em notação de função
de expressão, portanto, os símbolos e a notação disponíveis são os
mesmos em ambas as funções.
# https://cran.r-project.org/web/packages/latex2exp/vignettes/using-latex2exp.html
# https://www.cmor-faculty.rice.edu/~heinken/latex/symbols.pdf
plot(latex2exp::TeX(r'(A $\LaTeX$ fórmula: $\frac{2hc^2}{\lambda^5}\frac{1}{e^{\frac{hc}{\lambda k_B T}} - 1}$)'),
cex=2, main="")
x <- seq(0, 4, length.out=100)
alpha <- 1:5
plot(x, xlim=c(0, 4), ylim=c(0, 10),
xlab='x', ylab=latex2exp::TeX(r'($\alpha x^\alpha$, where $\alpha \in \{1 \ldots 5\}$)'),
type='n', main=latex2exp::TeX(r'(Using $\LaTeX$ for plotting in base graphics!)', bold=TRUE))
for (a in alpha) {
lines(x, a*x^a, col=a)
}
legend('topleft',
legend=latex2exp::TeX(sprintf(r'($\alpha = %d$)', alpha)),
bty="n",
lwd=1,
col=alpha)
Fig. 7.26. Apresentação em perspectiva de três pontos de uma superfície mostrando a inter-relação teórica dos genótipos do hospedeiro e do patógeno no controle da gravidade de uma doença.
Quatrocentos metros cúbicos de um produto granular devem ser transportados para outro lado do rio por meio de um serviço de ferryboat. Qualquer quantidade do produto pode ser transportada em uma viagem que custa dez centavos por viagem. Os ancoradouros do ferryboat estão construídos de modo que o contêiner no qual o produto vai ser transportado deve ter meio metro de profundidade, ao passo que a largura e o comprimento podem variar. Os custos por metro quadrado das superfícies terminais (da parte da frente à parte detrás), laterais e do fundo do contêiner são R$ 20, R$ 10 e R$ 10, respectivamente. Se o tamanho do contêiner for pequeno, seu custo poderá ser baixo, mas o número de viagens será maior, aumentando o custo do transporte e vice-versa.
Quais são os valores do comprimento e largura em metro do contêiner, isto é, quais as dimensões do contêiner que minimizam o custo total do transporte do produto granular?
Dimensões do contêiner.
Solução:
\(a\) : largura da base retangular do contêiner (m)
\(b\) : comprimento da base retangular do contêiner (m)
A função do custo total de transporte do produto granular por via fluvial é dada por:
\[ C(a,b)=\dfrac{80}{ab}+20a+10b+10ab \]
O contêiner de 0.5 m de altura, 1 m de largura e 2 m de comprimento, isto é, de 1 m3, realiza 400 viagens. O custo total mínimo do transporte fluvial de produto granular é R$ 100, isto é, \(C_{\text{min}}(1,2)=100\).
pracma
do Rf <- function(ab) {
a <- ab[1]; b <- ab[2]
80 / (a * b) + 20 * a + 10 * b + 10 * a * b
}
pracma::ezcontour(f,
xlim = c(0.5, 2),
ylim = c(1, 3))
ggplot2
, rayshader
e
plotly
do Rf <- function(a, b) {
80 / (a * b) + 20 * a + 10 * b + 10 * a * b
}
a_values <- seq(0.5, 2, length.out = 100)
b_values <- seq(1, 3, length.out = 100)
grid <- base::expand.grid(a = a_values, b = b_values)
grid$z <- base::with(grid, f(a, b))
grid_melt <- reshape2::melt(grid,
id.vars = c("a", "b"),
measure.vars = "z")
ggplot_contour <- ggplot2::ggplot(grid_melt,
ggplot2::aes(x = a,
y = b,
z = value)) +
ggplot2::geom_tile(ggplot2::aes(fill = value)) +
ggplot2::geom_contour(color = "black") +
ggplot2::scale_fill_gradientn(colours = grDevices::terrain.colors(10)) +
ggplot2::labs(title = "Gráfico de Contorno",
x = "a", y = "b", fill = "C") +
ggplot2::theme_minimal()
print(ggplot_contour)
rayshader::plot_gg(ggplot_contour,
multicore = TRUE,
zoom = 0.8, phi = 40, theta = 30)
rayshader::render_snapshot(clear = FALSE)
fig <- plotly::plot_ly(x = ~a_values,
y = ~b_values,
z = ~base::matrix(grid$z, nrow = 100))
fig <- plotly::add_surface(fig,
contours = list(
z = list(
show = TRUE,
usecolormap = TRUE,
highlightcolor = "#ff0000",
project = list(z = TRUE)
)
))
fig <- plotly::layout(fig,
scene = list(
xaxis = list(title = "a"),
yaxis = list(title = "b"),
zaxis = list(title = "C"),
camera = list(
eye = list(x = 1.87, y = 0.88, z = -0.64)
)
),
title = "Superfície 3D da Função")
fig
grad_f <- function(a, b) {
c(-80 / (a^2 * b) + 20 + 10 * b, -80 / (a * b^2) + 10 + 10 * a)
}
a <- seq(0.5, 2, length.out = 5)
b <- seq(1, 3, length.out = 3)
grid <- expand.grid(a = a, b = b)
grid$z <- mapply(f, grid$a, grid$b)
gradients <- t(mapply(grad_f, grid$a, grid$b))
grid$u <- gradients[, 1]
grid$v <- gradients[, 2]
g <- ggplot2::ggplot(grid, ggplot2::aes(x = a, y = b)) +
ggplot2::geom_tile(ggplot2::aes(fill = z), alpha = 0.3) +
ggplot2::geom_segment(ggplot2::aes(xend = a + u,
yend = b + v),
arrow = ggplot2::arrow(length =
ggplot2::unit(0.2,
"cm")),
color = "darkgray") +
ggplot2::scale_fill_gradient(low = "white", high = "black") +
ggplot2::labs(title = "Vetor Gradiente de f(a, b) = 80/(ab) + 20a + 10b + 10ab",
x = "a", y = "b") +
ggplot2::geom_point(ggplot2::aes(x = 1, y = 2), color = "blue",
size = 3) +
ggplot2::theme_minimal()
print(g)
extrema 80/(a b) + 20 a+ 10 b + 10 a b for a>0 and b>0
minimize 80/(a b) + 20 a+ 10 b + 10 a b for a>0 and b>0
ggplot2
, rayshader
e plotly
Maungawhau / Mount Eden: Wikipedia
Mount Eden é o vulcão mais alto de Auckland, Nova Zelândia, oferecendo algumas das melhores vistas de toda a cidade. Ele chega a 196 metros (643 pés) de altura e foi formado há cerca de 30.000 anos.
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] 100 100 101 101 101 101 101 100 100 100 101 101 102
[2,] 101 101 102 102 102 102 102 101 101 101 102 102 103
[3,] 102 102 103 103 103 103 103 102 102 102 103 103 104
[4,] 103 103 104 104 104 104 104 103 103 103 103 104 104
[5,] 104 104 105 105 105 105 105 104 104 103 104 104 105
[6,] 105 105 105 106 106 106 106 105 105 104 104 105 105
[7,] 105 106 106 107 107 107 107 106 106 105 105 106 106
[8,] 106 107 107 108 108 108 108 107 107 106 106 107 108
[9,] 107 108 108 109 109 109 109 108 108 107 108 108 110
[10,] 108 109 109 110 110 110 110 109 109 108 110 110 113
[11,] 109 110 110 111 111 111 111 110 110 110 112 114 118
[12,] 110 110 111 113 112 111 113 112 112 114 116 119 121
[13,] 110 111 113 115 114 113 114 114 115 117 119 121 124
[14,] 111 113 115 117 116 115 116 117 117 119 121 124 126
[15,] 114 115 117 117 117 118 119 119 120 121 124 126 128
[16,] 116 118 118 118 120 121 121 122 122 123 125 128 130
[17,] 118 120 120 121 122 123 124 124 125 126 127 129 132
[18,] 120 121 122 123 124 125 126 127 127 128 130 132 134
[19,] 120 122 125 126 126 127 128 129 130 130 132 134 136
[20,] 121 124 126 128 129 129 130 131 132 133 135 137 139
[21,] 122 125 127 130 130 131 133 134 135 136 137 140 143
[22,] 122 125 128 130 132 133 135 136 137 139 140 143 147
[23,] 123 126 129 131 133 135 137 138 139 141 143 147 150
[24,] 124 127 130 132 135 137 138 140 142 144 147 149 154
[25,] 123 128 131 133 136 138 140 142 144 146 149 151 154
[26,] 123 127 131 134 136 138 140 142 144 147 149 151 154
[27,] 120 124 128 131 134 137 139 142 144 146 149 151 153
[28,] 118 121 125 129 132 134 137 140 142 145 147 149 151
[29,] 117 120 121 125 129 132 135 138 140 143 145 147 149
[30,] 115 118 120 122 126 130 133 136 138 141 143 145 148
[31,] 114 116 118 120 122 127 131 133 136 138 141 143 146
[32,] 115 114 116 118 120 122 127 129 132 136 139 141 143
[33,] 113 113 114 116 118 120 122 125 129 133 136 138 141
[34,] 111 112 113 114 116 118 120 122 126 130 133 136 139
[35,] 110 112 113 113 114 116 118 120 123 127 131 134 137
[36,] 109 110 111 112 114 116 118 119 120 124 128 131 136
[37,] 108 109 111 112 114 116 117 118 120 121 125 128 132
[38,] 108 109 111 113 114 116 117 118 119 120 122 126 130
[39,] 107 108 111 112 114 115 116 117 119 120 121 124 128
[40,] 107 108 110 112 113 113 115 116 118 120 122 125 128
[41,] 107 108 109 111 113 114 116 117 119 120 122 125 128
[42,] 108 109 110 112 114 115 116 117 119 120 122 126 129
[43,] 109 110 111 113 115 116 117 118 120 121 123 126 129
[44,] 110 111 112 113 116 117 118 119 120 122 125 127 130
[45,] 111 112 113 114 116 117 118 119 120 123 125 128 130
[46,] 111 112 113 115 117 118 118 120 121 124 126 128 131
[47,] 112 113 114 116 117 118 119 120 122 124 127 129 132
[48,] 113 114 115 116 117 119 119 120 122 125 127 129 132
[49,] 113 114 115 117 118 119 120 121 123 125 127 130 132
[50,] 114 115 116 117 118 119 120 121 123 126 128 130 133
[51,] 115 116 117 118 119 120 121 121 123 126 128 131 134
[52,] 115 116 117 118 119 120 121 122 123 125 128 131 134
[53,] 114 115 116 116 118 119 120 121 122 126 129 132 135
[54,] 113 114 115 116 117 118 119 120 123 126 129 132 135
[55,] 112 113 114 115 116 117 119 120 122 126 130 133 136
[56,] 111 112 114 115 116 117 118 120 122 125 131 134 137
[57,] 111 112 113 115 115 116 117 119 121 126 131 135 138
[58,] 112 113 113 114 115 116 117 119 122 127 132 135 139
[59,] 112 113 114 114 116 117 118 120 122 128 132 136 139
[60,] 112 114 114 115 116 117 119 120 122 128 133 136 140
[61,] 113 114 115 116 116 117 118 120 123 129 133 137 140
[62,] 114 115 115 116 117 118 118 120 123 129 133 137 140
[63,] 114 115 116 117 117 119 118 120 123 128 132 136 139
[64,] 115 116 116 117 118 119 119 120 124 128 132 136 139
[65,] 115 116 117 118 118 119 120 123 125 128 131 135 138
[66,] 116 117 118 118 119 120 122 123 125 128 131 134 137
[67,] 116 117 118 119 120 121 123 124 126 128 130 133 137
[68,] 117 118 119 119 120 121 123 124 126 128 129 131 135
[69,] 117 118 119 120 120 121 123 124 125 126 128 129 132
[70,] 116 117 118 120 120 121 122 123 124 125 126 128 130
[71,] 114 115 116 117 119 119 120 121 122 123 125 127 129
[72,] 112 113 114 115 116 116 117 119 120 122 124 126 127
[73,] 109 111 112 112 113 113 113 114 116 119 121 123 124
[74,] 106 107 108 108 109 110 110 112 113 114 117 119 120
[75,] 104 105 105 106 106 107 108 108 109 109 111 115 116
[76,] 102 103 103 104 104 105 106 106 107 108 109 111 112
[77,] 101 102 103 103 104 105 105 106 106 107 108 109 109
[78,] 100 101 102 102 103 103 104 104 105 106 106 107 106
[79,] 100 101 101 102 102 103 103 104 104 105 105 105 105
[80,] 99 100 101 102 102 103 103 103 104 104 104 104 103
[81,] 99 100 100 101 101 102 102 102 103 103 103 103 102
[82,] 99 100 100 100 101 101 101 102 102 103 102 102 101
[83,] 99 99 99 99 100 100 101 101 102 102 101 101 101
[84,] 98 99 99 99 99 100 100 101 101 102 101 100 100
[85,] 98 98 98 99 99 99 100 100 101 101 100 100 99
[86,] 97 98 98 98 99 99 99 100 100 100 100 100 99
[87,] 97 97 97 98 98 99 99 99 100 100 100 99 99
[,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
[1,] 102 102 102 103 104 103 102 101 101 102 103 104
[2,] 103 103 103 104 105 104 103 102 102 103 105 106
[3,] 104 104 104 105 106 105 104 104 105 106 107 108
[4,] 104 105 105 106 107 106 106 106 107 108 110 111
[5,] 105 105 106 107 108 108 108 109 110 112 114 115
[6,] 106 106 107 109 110 110 112 113 115 116 118 119
[7,] 107 108 109 111 113 114 116 118 120 121 122 123
[8,] 108 110 113 115 117 118 120 122 124 125 127 128
[9,] 111 113 116 118 120 123 125 127 129 130 132 134
[10,] 116 118 120 122 125 127 129 133 136 138 140 141
[11,] 121 123 125 127 129 133 137 141 143 145 146 148
[12,] 124 127 129 133 138 143 146 149 149 151 153 154
[13,] 126 129 133 140 145 150 154 155 155 157 159 161
[14,] 128 132 137 143 151 156 161 161 162 163 165 166
[15,] 131 137 143 150 156 160 163 165 168 170 171 172
[16,] 134 141 147 152 156 160 165 168 170 174 176 179
[17,] 135 142 149 153 157 161 166 170 174 178 180 182
[18,] 137 142 151 155 158 162 169 172 176 181 183 184
[19,] 139 145 152 157 160 167 172 175 178 181 185 186
[20,] 143 150 154 159 164 170 173 176 179 184 186 189
[21,] 147 154 158 162 166 171 174 177 181 186 189 190
[22,] 152 157 161 164 168 172 175 179 182 186 190 190
[23,] 156 161 164 167 170 173 177 181 184 187 188 190
[24,] 157 161 165 168 171 175 178 181 184 186 187 187
[25,] 157 160 164 168 172 175 178 181 183 184 184 185
[26,] 157 160 164 168 171 174 178 180 181 181 182 183
[27,] 156 160 163 167 171 174 178 180 180 180 180 180
[28,] 155 159 163 166 169 173 177 179 180 180 180 180
[29,] 153 157 160 163 166 171 174 177 179 180 180 180
[30,] 151 154 157 160 163 168 171 174 177 179 179 179
[31,] 148 151 154 157 160 164 168 171 174 178 178 179
[32,] 146 148 151 153 156 160 164 167 172 174 176 177
[33,] 143 146 149 150 153 156 160 165 170 173 176 176
[34,] 142 145 147 148 151 155 158 163 168 173 176 177
[35,] 141 143 145 148 150 154 157 161 166 171 176 178
[36,] 140 142 145 147 150 153 157 160 165 170 174 178
[37,] 138 142 144 147 149 153 156 160 164 170 174 178
[38,] 135 139 143 147 149 152 156 160 164 169 173 177
[39,] 133 137 141 145 149 152 156 160 164 168 172 176
[40,] 132 136 140 145 148 150 155 160 164 167 170 174
[41,] 132 137 141 144 146 149 152 157 162 166 168 171
[42,] 133 137 141 143 146 148 151 155 160 164 167 168
[43,] 133 138 141 143 146 148 150 155 159 163 165 166
[44,] 133 138 141 143 146 148 150 154 159 162 163 164
[45,] 134 139 141 144 146 148 151 154 158 161 164 166
[46,] 135 139 142 144 146 148 151 155 160 164 165 168
[47,] 135 139 142 144 146 149 152 157 162 167 169 170
[48,] 135 139 142 144 147 149 154 159 164 169 170 170
[49,] 135 139 142 145 148 150 156 161 166 170 170 170
[50,] 136 139 142 145 148 152 157 161 166 168 170 170
[51,] 136 139 142 145 149 152 157 161 163 164 166 168
[52,] 137 139 142 145 149 152 156 159 159 160 162 162
[53,] 137 140 143 146 149 152 155 156 157 158 159 159
[54,] 138 140 143 146 148 151 153 154 156 157 157 157
[55,] 138 141 143 146 148 150 152 154 155 155 155 155
[56,] 139 142 144 146 148 150 152 153 153 153 153 153
[57,] 140 142 144 146 148 150 151 151 151 151 151 151
[58,] 141 143 145 147 149 150 150 150 150 150 150 150
[59,] 141 144 146 147 149 150 150 150 150 150 150 150
[60,] 142 144 146 148 150 150 150 150 150 150 150 150
[61,] 142 144 146 149 150 150 150 150 150 150 150 150
[62,] 143 145 147 150 150 150 150 150 150 150 150 150
[63,] 142 145 148 150 150 150 150 150 150 150 150 150
[64,] 142 145 148 150 150 150 150 150 150 150 150 150
[65,] 141 145 148 150 150 150 150 150 150 150 150 150
[66,] 141 145 148 149 150 150 150 150 150 150 150 148
[67,] 140 144 145 147 148 149 150 149 149 147 146 144
[68,] 139 142 143 145 146 147 147 147 146 144 142 140
[69,] 137 140 142 143 143 144 144 144 143 141 139 137
[70,] 134 139 140 141 141 141 141 141 140 138 136 134
[71,] 133 136 134 134 136 138 138 137 137 135 133 132
[72,] 129 129 128 127 129 132 133 133 133 133 131 129
[73,] 125 124 123 123 123 125 127 129 129 128 128 127
[74,] 121 119 117 117 117 118 120 123 124 125 125 125
[75,] 114 113 112 111 110 111 113 116 119 122 122 122
[76,] 110 109 108 108 108 108 109 110 112 116 117 117
[77,] 107 106 106 105 105 105 106 107 108 109 110 111
[78,] 106 106 105 105 104 103 103 104 105 107 108 110
[79,] 106 105 105 104 103 102 101 102 103 104 106 107
[80,] 104 104 104 104 102 101 101 102 103 104 105 107
[81,] 103 103 104 103 102 101 101 101 102 103 104 106
[82,] 102 102 103 103 101 101 100 101 101 102 103 105
[83,] 101 101 102 102 101 100 100 101 101 101 103 104
[84,] 100 101 101 101 100 100 100 100 101 101 101 103
[85,] 99 100 100 100 100 100 100 100 101 101 101 102
[86,] 99 99 100 100 100 100 100 100 100 101 101 101
[87,] 99 99 99 100 100 100 100 100 100 101 101 100
[,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
[1,] 104 105 107 107 107 108 108 110 110 110 110 110
[2,] 106 107 109 110 110 110 110 111 112 113 114 116
[3,] 110 111 113 114 115 114 115 116 118 119 119 121
[4,] 114 117 118 117 119 120 121 122 124 125 126 127
[5,] 118 121 122 121 123 128 131 129 130 131 131 132
[6,] 121 124 126 126 129 134 137 137 136 136 135 136
[7,] 125 127 129 130 135 140 142 142 142 141 140 140
[8,] 129 131 134 135 141 146 147 146 146 145 144 144
[9,] 135 137 139 142 146 152 152 151 151 150 149 148
[10,] 142 148 150 151 156 158 159 158 157 158 158 154
[11,] 150 154 156 159 161 162 163 164 163 164 164 160
[12,] 157 159 160 163 165 166 167 168 168 168 168 166
[13,] 162 164 165 167 168 169 170 172 174 172 172 171
[14,] 167 168 170 171 173 175 177 179 178 177 176 176
[15,] 173 174 175 177 179 180 182 183 183 183 183 180
[16,] 180 181 181 182 182 183 184 186 187 187 184 184
[17,] 183 184 184 185 186 186 187 189 189 189 189 189
[18,] 186 187 188 189 189 189 189 190 190 191 190 190
[19,] 188 190 191 192 193 193 192 192 191 192 191 191
[20,] 190 191 192 193 194 195 194 193 192 191 191 191
[21,] 190 191 192 191 191 190 189 188 189 190 190 191
[22,] 190 190 189 187 184 184 183 182 182 183 183 183
[23,] 189 187 185 183 179 176 174 174 174 174 174 176
[24,] 184 184 181 179 175 171 169 168 168 168 169 170
[25,] 183 180 177 174 170 167 165 164 164 164 165 166
[26,] 181 178 173 169 166 163 161 161 160 160 161 163
[27,] 180 175 171 167 162 160 158 157 157 157 158 159
[28,] 179 174 169 166 161 158 156 154 153 153 154 156
[29,] 179 172 168 164 160 157 154 151 149 150 150 154
[30,] 176 171 167 164 160 156 153 149 148 149 151 155
[31,] 177 173 169 165 161 157 154 151 149 150 152 155
[32,] 176 173 170 166 162 159 157 154 153 154 155 158
[33,] 176 173 172 169 165 163 160 158 157 158 159 161
[34,] 177 176 174 171 169 166 164 161 161 162 164 165
[35,] 178 178 176 174 172 170 167 167 167 166 168 170
[36,] 179 179 178 178 176 174 171 170 170 170 168 167
[37,] 180 180 179 179 178 176 172 170 170 170 168 166
[38,] 180 180 180 180 179 178 174 170 170 168 167 165
[39,] 179 180 180 180 179 178 174 170 168 166 165 163
[40,] 177 179 179 178 176 176 173 169 166 164 163 161
[41,] 173 175 175 173 172 172 171 168 165 162 160 158
[42,] 169 170 170 169 168 167 168 166 163 160 158 155
[43,] 167 168 168 166 165 164 161 160 159 158 155 152
[44,] 166 166 166 165 163 161 159 157 156 155 153 150
[45,] 167 168 166 165 163 161 158 156 154 152 150 146
[46,] 169 169 168 166 163 160 158 156 153 151 148 145
[47,] 170 170 168 165 163 161 159 157 155 151 148 145
[48,] 170 170 170 168 165 163 161 158 155 151 148 145
[49,] 170 170 170 169 166 163 161 159 155 151 148 146
[50,] 170 170 168 166 164 163 160 159 155 151 148 146
[51,] 167 166 164 163 161 160 158 156 152 149 147 144
[52,] 161 161 160 159 158 157 155 153 150 148 146 145
[53,] 159 158 158 157 155 153 151 150 149 147 146 145
[54,] 157 156 155 154 152 150 149 148 147 146 145 144
[55,] 155 154 152 152 150 148 147 146 145 145 143 142
[56,] 153 153 151 149 147 146 144 144 143 143 142 141
[57,] 151 151 150 148 146 144 142 141 141 142 141 140
[58,] 150 150 149 147 144 142 141 140 140 140 140 140
[59,] 150 150 149 146 143 141 140 140 139 139 139 140
[60,] 150 150 148 145 142 140 138 138 138 137 138 140
[61,] 150 150 147 143 141 139 137 136 136 135 136 138
[62,] 150 148 145 142 139 138 136 135 134 134 134 136
[63,] 150 147 144 141 139 136 135 134 133 132 132 134
[64,] 149 146 143 140 138 135 134 133 131 131 131 131
[65,] 147 145 142 139 137 134 132 131 130 129 128 128
[66,] 145 143 141 138 135 133 130 129 128 127 126 125
[67,] 141 139 136 133 131 129 128 127 126 125 124 123
[68,] 138 135 133 130 128 127 126 125 124 123 122 121
[69,] 135 133 130 128 127 126 125 123 122 121 120 119
[70,] 133 131 129 127 125 124 123 122 120 119 118 117
[71,] 130 129 127 125 124 122 121 120 119 117 116 115
[72,] 127 126 125 124 122 121 119 118 117 116 114 113
[73,] 125 124 123 122 121 119 118 117 116 114 113 112
[74,] 123 121 120 120 119 118 117 116 115 114 113 111
[75,] 121 120 119 118 118 117 116 115 114 113 112 111
[76,] 118 118 118 117 116 116 115 114 113 112 111 110
[77,] 113 114 115 115 115 114 113 112 111 110 108 108
[78,] 111 111 112 112 113 113 112 111 110 108 107 106
[79,] 110 111 111 111 112 112 112 110 107 107 106 105
[80,] 110 111 111 111 111 111 111 108 106 105 105 102
[81,] 109 110 111 111 111 110 110 107 105 103 104 100
[82,] 109 110 110 111 110 110 109 106 105 100 102 100
[83,] 107 109 109 110 110 109 108 105 102 100 100 99
[84,] 106 107 109 109 109 109 107 104 101 100 99 99
[85,] 105 106 109 108 109 107 105 102 100 100 99 99
[86,] 103 104 105 106 105 104 101 100 100 99 99 98
[87,] 100 100 100 100 100 100 100 100 100 99 99 98
[,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49]
[1,] 110 110 110 108 108 108 107 107 108 108 108 108
[2,] 115 114 112 110 110 110 109 108 109 109 109 109
[3,] 121 120 118 116 114 112 111 110 110 110 110 109
[4,] 127 126 124 122 120 117 116 113 111 110 110 110
[5,] 132 131 130 128 126 122 119 115 114 112 110 110
[6,] 136 136 135 133 129 126 122 118 116 115 113 111
[7,] 140 140 139 137 134 129 125 121 118 116 114 112
[8,] 144 143 142 141 139 135 130 126 122 118 116 114
[9,] 148 146 145 143 142 139 135 131 127 122 119 117
[10,] 151 149 148 146 144 141 137 134 130 125 122 120
[11,] 157 154 151 149 146 144 140 137 133 129 126 124
[12,] 162 159 157 154 152 149 144 140 136 133 131 128
[13,] 169 166 163 161 158 153 148 143 140 137 134 131
[14,] 174 171 169 165 161 156 152 148 144 140 138 135
[15,] 178 177 172 168 164 160 156 152 148 144 141 138
[16,] 181 180 176 172 168 165 161 157 153 149 145 142
[17,] 186 182 179 175 171 168 165 162 157 152 149 145
[18,] 188 186 183 180 175 171 168 165 161 157 152 149
[19,] 190 190 187 184 181 177 172 169 165 161 156 152
[20,] 191 190 190 188 184 181 177 173 169 165 160 155
[21,] 190 190 190 189 186 184 181 177 173 169 164 158
[22,] 184 185 186 187 186 185 184 181 177 173 169 163
[23,] 177 179 180 182 183 182 181 181 180 176 171 166
[24,] 172 174 177 178 179 180 181 181 180 179 174 167
[25,] 168 171 175 176 178 180 181 180 180 179 177 170
[26,] 165 168 173 176 178 179 180 181 180 180 175 173
[27,] 162 166 170 175 177 178 180 181 181 180 178 175
[28,] 159 163 169 173 175 178 180 181 180 180 179 175
[29,] 158 164 169 174 178 180 180 180 180 178 177 175
[30,] 158 163 170 173 177 179 180 180 180 178 175 173
[31,] 159 166 171 175 177 179 180 180 179 176 174 171
[32,] 161 169 172 174 176 178 178 178 178 175 172 169
[33,] 166 170 170 173 175 176 178 176 173 171 168 164
[34,] 167 170 170 171 173 173 173 170 168 165 163 160
[35,] 169 168 167 168 168 168 168 167 165 163 160 156
[36,] 166 164 163 161 162 163 163 163 161 160 157 153
[37,] 164 162 160 157 156 157 158 158 156 153 151 149
[38,] 163 161 157 154 153 152 152 152 149 148 147 144
[39,] 161 158 154 150 149 148 146 145 143 143 143 140
[40,] 159 155 152 148 145 143 141 140 139 139 138 136
[41,] 156 153 149 145 142 139 138 137 136 135 133 131
[42,] 153 150 147 143 140 137 136 134 133 132 130 129
[43,] 149 147 144 141 138 135 134 132 130 129 128 126
[44,] 146 143 140 138 136 133 132 130 129 128 125 124
[45,] 142 139 137 135 133 131 130 129 128 127 125 123
[46,] 142 139 137 135 132 130 129 127 126 125 124 123
[47,] 141 139 136 134 132 130 128 127 126 124 123 122
[48,] 142 139 137 135 132 131 128 126 125 124 122 121
[49,] 143 140 138 135 134 132 130 127 125 123 121 120
[50,] 143 141 138 136 134 132 130 128 125 123 121 120
[51,] 143 141 139 136 134 132 130 128 125 122 120 120
[52,] 143 142 140 137 134 131 129 126 124 122 120 119
[53,] 144 142 141 138 135 132 128 125 122 120 118 117
[54,] 142 141 140 139 136 132 129 125 121 118 116 115
[55,] 141 140 140 140 137 133 129 125 120 117 115 111
[56,] 140 140 140 140 138 134 130 123 120 118 111 110
[57,] 140 140 140 140 140 136 132 126 120 115 110 110
[58,] 140 140 140 140 140 137 133 128 120 117 110 110
[59,] 140 140 140 140 140 137 133 129 121 118 110 110
[60,] 140 140 140 140 140 137 134 130 122 118 110 110
[61,] 140 140 140 140 139 136 134 130 123 119 113 109
[62,] 138 137 138 139 137 134 132 125 122 117 114 109
[63,] 134 134 134 135 133 131 128 124 120 116 113 110
[64,] 131 131 131 130 127 124 122 119 117 115 112 109
[65,] 128 128 128 126 123 121 119 116 114 112 110 108
[66,] 125 125 124 123 120 118 116 114 111 109 107 106
[67,] 123 122 121 120 118 116 114 112 108 107 105 103
[68,] 120 119 118 117 115 114 112 110 106 105 102 101
[69,] 117 116 115 114 112 111 108 107 105 100 100 100
[70,] 116 114 112 111 108 109 106 106 100 100 100 100
[71,] 114 112 110 109 108 107 105 105 100 100 100 100
[72,] 112 110 109 108 106 106 105 100 100 100 98 98
[73,] 110 109 108 107 106 105 100 100 100 97 97 97
[74,] 109 109 107 106 105 100 100 100 96 96 96 96
[75,] 108 108 106 105 100 100 100 96 96 96 96 96
[76,] 107 107 105 100 100 100 97 96 96 96 96 96
[77,] 106 105 100 100 100 97 97 96 96 96 96 96
[78,] 105 100 100 100 98 97 97 96 96 96 96 96
[79,] 102 100 100 99 98 97 97 96 96 96 96 96
[80,] 101 100 99 99 98 97 97 96 96 96 96 96
[81,] 100 99 99 98 98 97 97 96 96 96 96 96
[82,] 99 99 99 98 98 97 97 96 96 96 96 96
[83,] 99 99 98 98 98 97 96 96 96 96 96 95
[84,] 99 98 98 98 97 96 96 96 96 95 95 95
[85,] 98 98 98 97 96 96 96 96 95 95 95 95
[86,] 98 97 97 97 96 96 96 95 95 95 95 95
[87,] 97 97 97 96 96 96 95 95 95 95 94 94
[,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61]
[1,] 108 107 107 107 107 106 106 105 105 104 104 103
[2,] 108 108 108 108 107 107 106 106 105 105 104 104
[3,] 109 109 109 108 108 107 107 106 106 105 105 104
[4,] 109 109 109 109 108 108 107 107 106 106 105 105
[5,] 110 110 110 109 109 108 107 107 107 106 106 105
[6,] 110 110 110 110 109 108 108 108 107 107 106 106
[7,] 110 110 110 111 110 109 109 108 108 107 107 106
[8,] 112 112 113 112 110 110 109 109 108 108 107 106
[9,] 115 115 115 114 112 110 110 109 109 108 107 107
[10,] 118 117 117 115 113 111 110 110 109 108 107 107
[11,] 121 119 118 116 114 112 111 110 109 108 107 106
[12,] 125 122 119 117 115 113 111 110 109 108 107 106
[13,] 128 125 120 118 116 114 112 110 109 108 107 105
[14,] 131 127 123 119 117 115 113 111 110 108 106 105
[15,] 134 130 126 121 117 114 112 110 110 108 106 104
[16,] 138 133 129 125 120 115 111 110 110 108 106 104
[17,] 141 137 131 125 120 116 111 110 110 108 106 104
[18,] 145 141 134 127 121 116 112 110 110 108 106 104
[19,] 147 143 139 131 123 119 115 111 110 108 106 105
[20,] 149 145 142 136 129 123 118 114 110 108 108 107
[21,] 152 148 144 140 134 125 118 115 111 110 108 107
[22,] 157 149 145 141 136 130 119 116 112 110 108 106
[23,] 160 152 147 142 138 133 126 121 115 110 106 105
[24,] 161 155 148 144 139 134 128 121 115 110 106 105
[25,] 163 157 150 144 139 134 128 121 115 110 108 107
[26,] 166 159 152 145 139 134 127 121 115 110 109 108
[27,] 169 160 154 148 140 134 128 121 115 110 110 109
[28,] 170 160 154 149 142 135 128 122 116 111 110 110
[29,] 170 161 153 148 142 135 129 123 116 113 112 110
[30,] 171 162 154 147 141 136 130 124 117 115 112 110
[31,] 168 159 151 146 141 135 129 124 119 116 113 110
[32,] 162 156 149 144 140 134 128 123 118 115 112 110
[33,] 158 153 146 140 137 132 127 121 117 113 111 110
[34,] 155 149 143 138 134 130 125 119 116 112 110 109
[35,] 152 146 140 136 131 128 122 118 114 110 110 109
[36,] 148 142 136 130 127 124 120 117 113 110 110 109
[37,] 144 139 130 127 124 121 118 115 112 110 110 109
[38,] 140 134 128 125 122 119 117 114 110 110 109 109
[39,] 136 130 126 123 120 118 115 112 110 110 109 109
[40,] 132 128 124 121 118 116 114 111 110 110 109 108
[41,] 129 126 122 119 117 114 112 110 110 109 108 107
[42,] 127 125 121 118 115 112 110 110 110 108 107 107
[43,] 124 122 120 117 113 111 110 110 110 108 107 107
[44,] 122 120 119 117 114 111 110 110 109 108 107 107
[45,] 121 120 118 116 113 111 110 110 109 108 107 106
[46,] 120 120 117 116 114 112 110 110 108 107 106 106
[47,] 120 119 117 116 114 112 111 109 107 106 106 105
[48,] 120 119 117 115 113 111 110 109 106 105 105 104
[49,] 120 119 116 114 112 110 110 108 106 105 104 104
[50,] 120 118 116 113 111 110 110 109 106 105 104 104
[51,] 119 117 115 113 110 110 109 107 106 105 104 104
[52,] 117 115 113 111 110 109 109 107 106 105 104 104
[53,] 115 113 112 110 109 108 108 106 105 105 104 104
[54,] 113 111 110 109 108 108 107 106 105 104 104 104
[55,] 110 110 109 108 107 107 106 105 105 104 104 103
[56,] 110 110 108 107 106 108 105 105 104 104 103 103
[57,] 110 109 107 106 105 107 105 104 104 104 103 103
[58,] 110 108 106 105 105 106 105 104 104 103 103 103
[59,] 109 107 106 105 105 105 104 104 103 103 103 102
[60,] 108 106 105 103 104 104 104 104 103 103 102 102
[61,] 108 106 104 103 104 104 104 103 103 102 102 101
[62,] 107 105 103 102 104 104 103 103 102 102 101 101
[63,] 107 104 102 102 103 103 103 102 102 102 101 100
[64,] 106 104 101 102 103 103 102 102 102 101 100 100
[65,] 105 103 101 103 103 103 102 102 101 100 100 100
[66,] 104 102 100 101 101 102 102 101 100 100 100 100
[67,] 102 100 100 100 100 101 101 100 100 100 100 100
[68,] 100 100 100 100 100 100 100 100 99 99 99 99
[69,] 100 100 100 100 99 99 99 99 99 99 99 98
[70,] 100 99 99 99 99 99 99 99 98 98 98 97
[71,] 99 99 99 98 98 98 98 98 97 97 97 97
[72,] 98 98 98 98 97 97 97 97 97 97 97 96
[73,] 97 97 97 97 96 96 96 96 96 96 96 96
[74,] 96 96 96 96 96 96 96 96 96 96 96 96
[75,] 96 96 96 96 96 96 96 96 96 96 96 96
[76,] 96 96 96 96 96 96 96 96 96 96 96 96
[77,] 96 96 96 96 96 96 96 96 96 96 96 96
[78,] 96 96 96 96 96 96 96 96 96 96 96 96
[79,] 96 96 96 96 96 96 96 96 96 96 96 95
[80,] 96 96 96 96 96 96 96 96 96 96 95 95
[81,] 96 96 96 96 96 95 95 95 95 95 95 95
[82,] 96 95 95 95 95 95 95 95 95 95 95 94
[83,] 95 95 95 95 95 95 94 94 94 94 94 94
[84,] 95 95 95 95 94 94 94 94 94 94 94 94
[85,] 95 95 94 94 94 94 94 94 94 94 94 94
[86,] 94 94 94 94 94 94 94 94 94 94 94 94
[87,] 94 94 94 94 94 94 94 94 94 94 94 94
# Gráfico interativo 3D com plotly
fig <- plotly::plot_ly(z = ~volcano)
fig <- plotly::add_surface(fig,
contours = list(
z = list(
show = TRUE,
usecolormap = TRUE,
highlightcolor = "#ff0000",
project = list(z = TRUE)
)
)
)
fig <- plotly::layout(fig,
scene = list(
camera = list(
eye = list(x = 1.87, y = 0.88, z = -0.64)
)
)
)
fig
# Gráficos base R
rx <- range(x <- 10 * 1:nrow(volcano))
ry <- range(y <- 10 * 1:ncol(volcano))
ry <- ry + c(-1, 1) * (diff(rx) - diff(ry)) / 2
tcol <- terrain.colors(12)
plot(x = 0, y = 0, type = "n", xlim = rx, ylim = ry, xlab = "", ylab = "")
u <- par("usr")
rect(u[1], u[3], u[2], u[4], col = "lightblue", border = "black")
contour(x, y, volcano, col = "black", lty = "solid", add = TRUE,
vfont = c("sans serif", "plain"))
title("A Topographic Map of Maunga Whau", font = 4)
abline(h = 200 * 0:4, v = 200 * 0:4, col = "white", lty = 2, lwd = 0.1)
plot(x = 0, y = 0, type = "n", xlim = rx, ylim = ry, xlab = "", ylab = "")
u <- par("usr")
rect(u[1], u[3], u[2], u[4], col = "lightblue", border = "black")
contour(x, y, volcano, col = "black", lty = "solid", add = TRUE,
vfont = c("sans serif", "plain"))
line.list <- contourLines(x, y, volcano)
invisible(lapply(line.list, lines, lwd = 3, col = adjustcolor(2, 0.3)))
abline(h = 200 * 0:4, v = 200 * 0:4, col = "white", lty = 2, lwd = 0.1)
filled.contour(volcano, color.palette = terrain.colors, asp = 1)
title(main = "volcano data: filled contour map")
filled.contour(x, y, volcano,
color.palette = function(n) hcl.colors(n, "terrain"),
plot.title = title(main = "The Topography of Maunga Whau",
xlab = "Meters North", ylab = "Meters West"),
plot.axes = {
axis(1, seq(100, 800, by = 100))
axis(2, seq(100, 600, by = 100))
},
key.title = title(main = "Height\n(meters)"),
key.axes = axis(4, seq(90, 190, by = 10))
)
mtext(paste("filled.contour(.) from", R.version.string),
side = 1, line = 4, adj = 1, cex = 0.66)
# Gráfico com ggplot2 (sem pipes)
volcano_melted <- reshape2::melt(volcano)
ggvolcano <- ggplot2::ggplot(data = volcano_melted) +
ggplot2::geom_tile(ggplot2::aes(x = Var1, y = Var2, fill = value)) +
ggplot2::geom_contour(ggplot2::aes(x = Var1, y = Var2, z = value), color = "black") +
ggplot2::scale_x_continuous("X", expand = c(0, 0)) +
ggplot2::scale_y_continuous("Y", expand = c(0, 0)) +
ggplot2::scale_fill_gradientn("Z", colours = terrain.colors(10)) +
ggplot2::coord_fixed()
print(ggvolcano)
# Transformar em 3D com rayshader
rayshader::plot_gg(ggvolcano,
multicore = TRUE,
zoom = 0.8,
phi = 40,
theta = 30)
rayshader::render_snapshot(clear = FALSE)
scatterplot3d::scatterplot3d
# Descrição
#
# Este conjunto de dados fornece medições de diâmetro, altura e volume de madeira em 31 cerejeiras-pretas derrubadas. Observe que o diâmetro (em polegadas) é rotulado erroneamente como Girth nos dados.
# É medido a 4 pés 6 em acima do solo.
#
# Um quadro de dados com 31 observações em 3 variáveis.
#
# Girth: Diâmetro da árvore (em vez de circunferência, na verdade) em polegadas
#
# Height: Altura numérica em pés
#
# Volume: volume numérico de madeira em pés cúbicos
# Add regression plane and supplementary points
data(trees) # Diameter, Height and Volume for Black Cherry Trees
head(trees)
# A tibble: 6 × 3
Girth Height Volume
<dbl> <dbl> <dbl>
1 8.3 70 10.3
2 8.6 65 10.3
3 8.8 63 10.2
4 10.5 72 16.4
5 10.7 81 18.8
6 10.8 83 19.7
# 3D scatter plot
s3d <- scatterplot3d::scatterplot3d(trees, type = "p", color = "blue",
angle=55, pch = 16)
# Add regression plane
my.lm <- lm(trees$Volume ~ trees$Girth + trees$Height)
s3d$plane3d(my.lm)
# Add supplementary points
s3d$points3d(mean(trees$Girth, na.rm=TRUE),
mean(trees$Height, na.rm=TRUE),
mean(trees$Volume, na.rm=TRUE),
col = "black", type = "p", pch = 16, cex=2)
s3d <- scatterplot3d::scatterplot3d(trees, type = "p", color = "blue",
angle=-45, pch = 16)
# Add regression plane
s3d$plane3d(my.lm)
# Add supplementary points
s3d$points3d(mean(trees$Girth, na.rm=TRUE),
mean(trees$Height, na.rm=TRUE),
mean(trees$Volume, na.rm=TRUE),
col = "black", type = "p", pch = 16, cex=2)
car::scatter3d
: executar no RStudio usando
Run# Descrição
#
# O _dataframe_ carData::Duncan (Duncan's Occupational Prestige Data) tem 45 linhas e 4 colunas.
#
# Dados sobre o prestígio e outras características de 45 ocupações
# nos Estados Unidos em 1950.
#
# Este quadro de dados contém as seguintes colunas:
#
# type
# Tipo de ocupação. Um fator com os seguintes níveis: profissional,
# profissional e gerencial; wc, colarinho branco; bc, colarinho azul.
#
# income
# Porcentagem de titulares ocupacionais no Censo dos EUA de 1950 que
# ganhavam US$ 3.500 ou mais por ano (cerca de US$ 36.000 em dólares
# americanos de 2017).
#
# education
# Porcentagem de titulares ocupacionais em 1950 que concluíram o ensino
# médio (o que, se fôssemos cínicos, diríamos que é aproximadamente
# equivalente a um doutorado em 2017)
#
# prestige
# Porcentagem de entrevistados em uma pesquisa social que classificaram a
# ocupação como “boa” ou melhor em prestígio
#
## Documentação do conjunto de dados Prestige {carData}
#
# Prestígio das Ocupações Canadenses
#
# Descrição:
# O data frame Prestige contém 102 linhas e 6 colunas. As observações representam ocupações.
#
# Formato:
# Este data frame contém as seguintes colunas:
#
# education
# Escolaridade média dos ocupantes das ocupações, em anos, no ano de 1971.
#
# income
# Renda média dos ocupantes, em dólares, no ano de 1971.
#
# women
# Percentual de ocupantes que são mulheres.
#
# prestige
# Escore de prestígio Pineo-Porter da ocupação, obtido por meio de uma pesquisa social
# conduzida em meados da década de 1960.
#
# census
# Código ocupacional do Censo Canadense.
#
# type
# Tipo de ocupação. Fator com os seguintes níveis (observação: fora de ordem alfabética):
# - bc: Colarinho Azul (Blue Collar)
# - prof: Profissional, Gerencial e Técnico (Professional, Managerial, and Technical)
# - wc: Colarinho Branco (White Collar)
car::scatter3d(prestige ~ income + education, data=carData::Duncan, id=list(n=3))
car::scatter3d(prestige ~ income + education | type, data=carData::Duncan)
car::scatter3d(prestige ~ income + education | type, surface=FALSE,
ellipsoid=TRUE, revolutions=3, data=carData::Duncan)
car::scatter3d(prestige ~ income + education, fit=c("linear", "additive"),
data=carData::Prestige)
car::scatter3d(prestige ~ income + education | type,
radius=(1 + women)^(1/3), data=carData::Prestige)
# Amazing interactive 3D scatter plots - R software and data visualization
# http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization
data(iris)
head(iris)
sep.l <- iris$Sepal.Length
pet.l <- iris$Petal.Length
sep.w <- iris$Sepal.Width
grp <- iris$Species
car::scatter3d(x = sep.l, y = pet.l, z = sep.w)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w,
point.col = "blue", surface=FALSE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
grid = FALSE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
grid = FALSE, fit = "smooth")
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
grid = FALSE, surface = FALSE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
surface=FALSE, ellipsoid = TRUE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
surface=FALSE, grid = FALSE, ellipsoid = TRUE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
surface=FALSE, grid = FALSE, ellipsoid = TRUE,
surface.col = c("#999999", "#E69F00", "#56B4E9"))
colors <- RColorBrewer::brewer.pal(n=3, name="Dark2")
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
surface=FALSE, grid = FALSE, ellipsoid = TRUE,
surface.col = colors)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
point.col = "blue", surface=FALSE,
xlab = "Sepal Length (cm)", ylab = "Petal Length (cm)",
zlab = "Sepal Width (cm)")
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
point.col = "blue", surface=FALSE,
xlab = "Sepal Length (cm)", ylab = "Petal Length (cm)",
zlab = "Sepal Width (cm)",
axis.scales = FALSE)
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
point.col = "blue", surface=FALSE,
xlab = "Sepal Length (cm)", ylab = "Petal Length (cm)",
zlab = "Sepal Width (cm)",
axis.scales = FALSE,
axis.col = c("black", "black", "black"))
car::scatter3d(x = sep.l, y = pet.l, z = sep.w, groups = grp,
surface=FALSE, labels = rownames(iris), id.n=nrow(iris))
local({
set.seed(123)
Sigma <- matrix(c(
1, 0.5,
0.5, 1),
2, 2
)
X <- MASS::mvrnorm(200, mu=c(0,0), Sigma=Sigma)
D <- data.frame(
x1 = X[, 1],
x2 = X[, 2]
)
D$y <- with(D, 10 + 1*x1 + 2*x2 + 3*x1*x2 + rnorm(200, sd=3))
# plot true regression function
car::scatter3d(y ~ x1 + x2, D,
reg.function=10 + 1*x + 2*z + 3*x*z,
surface=FALSE, revolutions=2)
})
plotly
, plot3D
e
regplane3D
do Rlibrary(dplyr)
Dados <- readxl::read_excel("PrePos.xlsx")
Dados <- dplyr::mutate_if(Dados, is.character, as.factor)
Dados <- dplyr::mutate_at(Dados, dplyr::vars(ID), as.factor)
Dados$Grupo <- factor(Dados$Grupo,
levels=c("Placebo", "Tratamento"),
labels=c("Placebo", "Tratamento"))
print(labelled::look_for(Dados[,-1]))
pos variable label col_type missing values
1 Grupo — fct 0 Placebo
Tratamento
2 Pre — dbl 0
3 Pos — dbl 0
ID Grupo Pre Pos
1 2 Placebo 9 8
2 9 Placebo 16 17
3 12 Placebo 9 10
4 17 Placebo 23 16
5 18 Placebo 18 16
6 20 Placebo 17 15
7 23 Placebo 7 5
8 1 Tratamento 22 21
9 3 Tratamento 44 47
10 8 Tratamento 8 28
11 10 Tratamento 16 26
12 11 Tratamento 9 38
13 14 Tratamento 29 31
14 16 Tratamento 30 38
15 15 Tratamento 30 38
16 21 Tratamento 30 31
17 24 Tratamento 13 17
item group1 vars n mean sd median trimmed mad min max range
Pre1 1 Placebo 1 7 14.14 5.90 16.0 14.14 10.38 7 23 16
Pre2 2 Tratamento 1 10 23.10 11.52 25.5 22.38 10.38 8 44 36
Pos1 3 Placebo 2 7 12.43 4.72 15.0 12.43 2.97 5 17 12
Pos2 4 Tratamento 2 10 31.50 9.01 31.0 31.38 10.38 17 47 30
skew kurtosis se
Pre1 0.10 -1.77 2.23
Pre2 0.18 -1.28 3.64
Pos1 -0.42 -1.77 1.78
Pos2 0.02 -1.17 2.85
# https://plotly.com/r/ml-regression/
Dados$Grupo.num <- as.numeric(Dados$Grupo)-1
out <- summary(fit <- lm(Pos ~ Grupo.num + Pre, data=Dados))
print(out)
Call:
lm(formula = Pos ~ Grupo.num + Pre, data = Dados)
Residuals:
Min 1Q Median 3Q Max
-9.9397 -3.5054 0.1912 2.9852 13.6825
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.2242 3.1922 1.637 0.123996
Grupo.num 14.5087 3.2732 4.433 0.000568 ***
Pre 0.5094 0.1595 3.194 0.006501 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 5.976 on 14 degrees of freedom
Multiple R-squared: 0.7883, Adjusted R-squared: 0.7581
F-statistic: 26.07 on 2 and 14 DF, p-value: 1.904e-05
fitpoints <- predict(fit)
cf <- coef(out)
grid.lines <- 5
x <- seq(min(Dados$Grupo.num),
max(Dados$Grupo.num),
length.out = grid.lines)
y <- seq(min(Dados$Pre),
max(Dados$Pre),
length.out = grid.lines)
response <- function(x,y){
cf[1] +
cf[2]*x +
cf[3]*y
}
z.pred <- outer(x, y, response)
fig <- plotly::plot_ly(Dados, x = ~Grupo.num, y = ~Pre, z = ~Pos)
fig <- plotly::add_markers(fig, size = 5)
fig <- plotly::add_surface(fig, x = x, y = y, z = z.pred,
contours = list(z = list(show = TRUE,
usecolormap = TRUE,
highlightcolor = "#ff0000",
project = list(z = TRUE))))
fig
# https://rpubs.com/pjozefek/576206
Dados <- na.omit(Dados)
Dados$Grupo.num <- as.numeric(Dados$Grupo)-1
out <- summary(fit <- lm(Pos ~ Grupo.num + Pre, data=Dados))
fitpoints <- predict(fit)
cf <- coef(out)
grid.lines <- 5
x <- seq(min(Dados$Grupo.num),
max(Dados$Grupo.num),
length.out = grid.lines)
y <- seq(min(Dados$Pre),
max(Dados$Pre),
length.out = grid.lines)
response <- function(x,y){
cf[1] +
cf[2]*x +
cf[3]*y
}
z.pred <- outer(x, y, response)
plot3D::persp3D(x = x,
y = y,
z = z.pred,
ticktype = "detailed",
border=NA,
facets=NA,
shade=0.5,
lighting=TRUE,
phi = 0,
theta = 35,
xlab = "Grupo",
ylab = "Pre",
zlab = "Pos^",
clab = "Pos",
main = "Delineamento Pré-Pós",
contour = FALSE,
cex.axis = 0.75,
cex.lab = 0.75)
plot3D::scatter3D(x = Dados$Grupo.num,
y = Dados$Pre,
z = Dados$Pos,
theta=0,
phi=35,
bty="b2",
cex=0.5,
expand=0.7,
colvar=FALSE,
surf = list(x = x, y = y, z = z.pred,
facets = NA,
fit = fitpoints,
col="gray",
# col=plot3D::ramp.col(col=c("dodgerblue3",
# "seagreen2"),
# n=300,
# alpha=0.9),
border="black"),
add = TRUE,
type = "h",
pch = 19,
col = "black",
lwd = 2,
colkey = FALSE)
## ---- Estimation ----
fit <- lm(Pos ~ Grupo.num + Pre, data=Dados)
n <- nrow(Dados)
## ---- Axis inputs ----
## Group.num
Grupo.num_axis <- regplane3D::pretty_axis_inputs(
axis_range = range(Dados$Grupo.num),
base = 1,
nlines_suggest = 5L,
multiply = 1
)
## FMAULpre
Pre_axis <- regplane3D::pretty_axis_inputs(
axis_range = range(Dados$Pre),
base = 10,
nlines_suggest = 5L,
multiply = 1
)
## ---- Prediction ----
pred <-
array(NA, dim = c(length(Grupo.num_axis$seq),
length(Pre_axis$seq), 3L))
for (Grupo.num in seq_along(Grupo.num_axis$seq)) {
for (Pre in seq_along(Pre_axis$seq)) {
pred_tmp <- predict.lm(
fit,
newdata = data.frame(Grupo.num = Grupo.num_axis$seq[Grupo.num],
Pre = Pre_axis$seq[Pre]),
se.fit = TRUE
)
# Applied linear statistical model - Kutner et al - 5e - 2004, p. 63
# Applied Multivariate Statistical Analysis - Johnson & Wichern - 6e - 2007, p. 212
pred[Grupo.num, Pre, ] <- c(
pred_tmp$fit,
pred_tmp$fit - sqrt(((n-1)/(n-2))*2*qf(0.95,2,n-2)) * pred_tmp$se.fit,
pred_tmp$fit + sqrt(((n-1)/(n-2))*2*qf(0.95,2,n-2)) * pred_tmp$se.fit
)
}
}
## ---- Plot ----
par(mar = c(2.1, 2.1, 4.1, 0.1))
regplane3D::plane3D(
z = pred,
x = Grupo.num_axis$seq,
y = Pre_axis$seq,
zlab = "Pos",
xlab = "Grupo",
ylab = "Pre",
zlim = c(-10, 60),
xlim = Grupo.num_axis$range,
ylim = Pre_axis$range,
xnlines = Grupo.num_axis$nlines,
ynlines = Pre_axis$nlines,
main = "Delineamento Pré-Pós",
theta = -45,
phi = 9
)
plot3D::points3D(
z = Dados$Pos,
x = Dados$Grupo.num,
y = Dados$Pre,
add = TRUE,
col = adjustcolor("black", alpha.f = .3),
pch = 19
)
plot3D::text3D(
z = Dados$Pos+2.5,
x = Dados$Grupo.num,
y = Dados$Pre,
labels = Dados$ID,
add = TRUE,
cex = 0.6
)
par(mar = c(2.1, 2.1, 4.1, 0.1))
regplane3D::plane3D(
z = pred,
x = Grupo.num_axis$seq,
y = Pre_axis$seq,
zlab = "Pos",
xlab = "Grupo",
ylab = "Pre",
zlim = c(-10, 60),
xlim = Grupo.num_axis$range,
ylim = Pre_axis$range,
xnlines = Grupo.num_axis$nlines,
ynlines = Pre_axis$nlines,
main = "Delineamento Pré-Pós",
theta = 0,
phi = -12
)
plot3D::points3D(
z = Dados$Pos,
x = Dados$Grupo.num,
y = Dados$Pre,
add = TRUE,
col = adjustcolor("black", alpha.f = .3),
pch = 19
)
yzmin <- min(c(c(pred),Pre_axis$range),na.rm=TRUE)*0.98
yzmax <- max(c(c(pred),Pre_axis$range),na.rm=TRUE)*1.02
quinas2z <- rep(NA,4)
idx <- 0
for (c.row in c(1,nrow(pred[,,2])))
{
for (c.col in c(1,ncol(pred[,,2])))
{
idx <- idx+1
quinas2z[idx] <- pred[c.row,c.col,2]
}
}
quinas3z <- rep(NA,4)
idx <- 0
for (c.row in c(1,nrow(pred[,,3])))
{
for (c.col in c(1,ncol(pred[,,3])))
{
idx <- idx+1
quinas3z[idx] <- pred[c.row,c.col,3]
}
}
yzminH0 <- max(quinas2z[c(1,3)])
yzmaxH0 <- min(quinas3z[c(2,4)])
par(mar = c(2.1, 2.1, 4.1, 0.1))
regplane3D::plane3D(
z = pred,
x = Grupo.num_axis$seq,
y = Pre_axis$seq,
zlab = "Pos",
xlab = "Grupo",
ylab = "Pre",
zlim = c(yzmin, yzmax),
xlim = Grupo.num_axis$range,
ylim = c(yzmin, yzmax),
xnlines = Grupo.num_axis$nlines,
ynlines = Pre_axis$nlines,
main = "Delineamento Pré-Pós",
theta = 45,
phi = 9
)
quinas_x <- Grupo.num_axis$seq[c(1,1,length(Grupo.num_axis$seq),length(Grupo.num_axis$seq))]
quinas_y <- Pre_axis$seq[c(1,length(Pre_axis$seq),1,length(Pre_axis$seq))]
# plot3D::points3D(
# z = quinas2z,
# x = quinas_x,
# y = quinas_y,
# add = TRUE,
# col = adjustcolor("black", alpha.f = .3),
# pch = 19
# )
# plot3D::points3D(
# z = quinas3[c(1,2,3,4)],
# x = quinas_x,
# y = quinas_y,
# add = TRUE,
# col = adjustcolor("black", alpha.f = .3),
# pch = 19
# )
plot3D::lines3D(
z = c(yzminH0,yzminH0,yzmaxH0,yzmaxH0,yzminH0),
x = c(0,1,1,0,0),
y = c(yzminH0,yzminH0,yzmaxH0,yzmaxH0,yzminH0),
col="darkblue",
lty=2,
add = TRUE
)
plot3D::points3D(
z = Dados$Pos,
x = Dados$Grupo.num,
y = Dados$Pre,
add = TRUE,
col = adjustcolor("black", alpha.f = .3),
pch = 19
)
par(mar = c(2.1, 2.1, 4.1, 0.1))
regplane3D::plane3D(
z = pred,
x = Grupo.num_axis$seq,
y = Pre_axis$seq,
zlab = "Pos",
xlab = "Grupo",
ylab = "Pre",
zlim = c(yzmin, yzmax),
xlim = Grupo.num_axis$range,
ylim = c(yzmin, yzmax),
xnlines = Grupo.num_axis$nlines,
ynlines = Pre_axis$nlines,
main = "Delineamento Pré-Pós",
theta = 0,
phi = -20
)
quinas_x <- Grupo.num_axis$seq[c(1,1,length(Grupo.num_axis$seq),length(Grupo.num_axis$seq))]
quinas_y <- Pre_axis$seq[c(1,length(Pre_axis$seq),1,length(Pre_axis$seq))]
# plot3D::points3D(
# z = quinas2z,
# x = quinas_x,
# y = quinas_y,
# add = TRUE,
# col = adjustcolor("black", alpha.f = .3),
# pch = 19
# )
# plot3D::points3D(
# z = quinas3[c(1,2,3,4)],
# x = quinas_x,
# y = quinas_y,
# add = TRUE,
# col = adjustcolor("black", alpha.f = .3),
# pch = 19
# )
plot3D::lines3D(
z = c(yzminH0,yzminH0,yzmaxH0,yzmaxH0,yzminH0),
x = c(0,1,1,0,0),
y = c(yzminH0,yzminH0,yzmaxH0,yzmaxH0,yzminH0),
col="darkblue",
lty=2,
add = TRUE
)
plot3D::points3D(
z = Dados$Pos,
x = Dados$Grupo.num,
y = Dados$Pre,
add = TRUE,
col = adjustcolor("black", alpha.f = .3),
pch = 19
)
Plotar função 3D em WolframAlpha
ParametricPlot3D em WolframAlpha
SphericalPlot3D em WolframAlpha
Gráficos 2D e 3D Melhorados em WOLFRAM MATHEMATICA
B-spline curve and its control points in 3D em WOLFRAM MATHEMATICA
[1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
[5] "antiquewhite2" "antiquewhite3"
[1] "yellow" "yellow1" "yellow2" "yellow3" "yellow4"
[6] "yellowgreen"
[1] "white" "aliceblue" "antiquewhite"
[4] "antiquewhite1" "antiquewhite2" "antiquewhite3"
[7] "antiquewhite4" "aquamarine" "aquamarine1"
[10] "aquamarine2" "aquamarine3" "aquamarine4"
[13] "azure" "azure1" "azure2"
[16] "azure3" "azure4" "beige"
[19] "bisque" "bisque1" "bisque2"
[22] "bisque3" "bisque4" "black"
[25] "blanchedalmond" "blue" "blue1"
[28] "blue2" "blue3" "blue4"
[31] "blueviolet" "brown" "brown1"
[34] "brown2" "brown3" "brown4"
[37] "burlywood" "burlywood1" "burlywood2"
[40] "burlywood3" "burlywood4" "cadetblue"
[43] "cadetblue1" "cadetblue2" "cadetblue3"
[46] "cadetblue4" "chartreuse" "chartreuse1"
[49] "chartreuse2" "chartreuse3" "chartreuse4"
[52] "chocolate" "chocolate1" "chocolate2"
[55] "chocolate3" "chocolate4" "coral"
[58] "coral1" "coral2" "coral3"
[61] "coral4" "cornflowerblue" "cornsilk"
[64] "cornsilk1" "cornsilk2" "cornsilk3"
[67] "cornsilk4" "cyan" "cyan1"
[70] "cyan2" "cyan3" "cyan4"
[73] "darkblue" "darkcyan" "darkgoldenrod"
[76] "darkgoldenrod1" "darkgoldenrod2" "darkgoldenrod3"
[79] "darkgoldenrod4" "darkgray" "darkgreen"
[82] "darkgrey" "darkkhaki" "darkmagenta"
[85] "darkolivegreen" "darkolivegreen1" "darkolivegreen2"
[88] "darkolivegreen3" "darkolivegreen4" "darkorange"
[91] "darkorange1" "darkorange2" "darkorange3"
[94] "darkorange4" "darkorchid" "darkorchid1"
[97] "darkorchid2" "darkorchid3" "darkorchid4"
[100] "darkred" "darksalmon" "darkseagreen"
[103] "darkseagreen1" "darkseagreen2" "darkseagreen3"
[106] "darkseagreen4" "darkslateblue" "darkslategray"
[109] "darkslategray1" "darkslategray2" "darkslategray3"
[112] "darkslategray4" "darkslategrey" "darkturquoise"
[115] "darkviolet" "deeppink" "deeppink1"
[118] "deeppink2" "deeppink3" "deeppink4"
[121] "deepskyblue" "deepskyblue1" "deepskyblue2"
[124] "deepskyblue3" "deepskyblue4" "dimgray"
[127] "dimgrey" "dodgerblue" "dodgerblue1"
[130] "dodgerblue2" "dodgerblue3" "dodgerblue4"
[133] "firebrick" "firebrick1" "firebrick2"
[136] "firebrick3" "firebrick4" "floralwhite"
[139] "forestgreen" "gainsboro" "ghostwhite"
[142] "gold" "gold1" "gold2"
[145] "gold3" "gold4" "goldenrod"
[148] "goldenrod1" "goldenrod2" "goldenrod3"
[151] "goldenrod4" "gray" "gray0"
[154] "gray1" "gray2" "gray3"
[157] "gray4" "gray5" "gray6"
[160] "gray7" "gray8" "gray9"
[163] "gray10" "gray11" "gray12"
[166] "gray13" "gray14" "gray15"
[169] "gray16" "gray17" "gray18"
[172] "gray19" "gray20" "gray21"
[175] "gray22" "gray23" "gray24"
[178] "gray25" "gray26" "gray27"
[181] "gray28" "gray29" "gray30"
[184] "gray31" "gray32" "gray33"
[187] "gray34" "gray35" "gray36"
[190] "gray37" "gray38" "gray39"
[193] "gray40" "gray41" "gray42"
[196] "gray43" "gray44" "gray45"
[199] "gray46" "gray47" "gray48"
[202] "gray49" "gray50" "gray51"
[205] "gray52" "gray53" "gray54"
[208] "gray55" "gray56" "gray57"
[211] "gray58" "gray59" "gray60"
[214] "gray61" "gray62" "gray63"
[217] "gray64" "gray65" "gray66"
[220] "gray67" "gray68" "gray69"
[223] "gray70" "gray71" "gray72"
[226] "gray73" "gray74" "gray75"
[229] "gray76" "gray77" "gray78"
[232] "gray79" "gray80" "gray81"
[235] "gray82" "gray83" "gray84"
[238] "gray85" "gray86" "gray87"
[241] "gray88" "gray89" "gray90"
[244] "gray91" "gray92" "gray93"
[247] "gray94" "gray95" "gray96"
[250] "gray97" "gray98" "gray99"
[253] "gray100" "green" "green1"
[256] "green2" "green3" "green4"
[259] "greenyellow" "grey" "grey0"
[262] "grey1" "grey2" "grey3"
[265] "grey4" "grey5" "grey6"
[268] "grey7" "grey8" "grey9"
[271] "grey10" "grey11" "grey12"
[274] "grey13" "grey14" "grey15"
[277] "grey16" "grey17" "grey18"
[280] "grey19" "grey20" "grey21"
[283] "grey22" "grey23" "grey24"
[286] "grey25" "grey26" "grey27"
[289] "grey28" "grey29" "grey30"
[292] "grey31" "grey32" "grey33"
[295] "grey34" "grey35" "grey36"
[298] "grey37" "grey38" "grey39"
[301] "grey40" "grey41" "grey42"
[304] "grey43" "grey44" "grey45"
[307] "grey46" "grey47" "grey48"
[310] "grey49" "grey50" "grey51"
[313] "grey52" "grey53" "grey54"
[316] "grey55" "grey56" "grey57"
[319] "grey58" "grey59" "grey60"
[322] "grey61" "grey62" "grey63"
[325] "grey64" "grey65" "grey66"
[328] "grey67" "grey68" "grey69"
[331] "grey70" "grey71" "grey72"
[334] "grey73" "grey74" "grey75"
[337] "grey76" "grey77" "grey78"
[340] "grey79" "grey80" "grey81"
[343] "grey82" "grey83" "grey84"
[346] "grey85" "grey86" "grey87"
[349] "grey88" "grey89" "grey90"
[352] "grey91" "grey92" "grey93"
[355] "grey94" "grey95" "grey96"
[358] "grey97" "grey98" "grey99"
[361] "grey100" "honeydew" "honeydew1"
[364] "honeydew2" "honeydew3" "honeydew4"
[367] "hotpink" "hotpink1" "hotpink2"
[370] "hotpink3" "hotpink4" "indianred"
[373] "indianred1" "indianred2" "indianred3"
[376] "indianred4" "ivory" "ivory1"
[379] "ivory2" "ivory3" "ivory4"
[382] "khaki" "khaki1" "khaki2"
[385] "khaki3" "khaki4" "lavender"
[388] "lavenderblush" "lavenderblush1" "lavenderblush2"
[391] "lavenderblush3" "lavenderblush4" "lawngreen"
[394] "lemonchiffon" "lemonchiffon1" "lemonchiffon2"
[397] "lemonchiffon3" "lemonchiffon4" "lightblue"
[400] "lightblue1" "lightblue2" "lightblue3"
[403] "lightblue4" "lightcoral" "lightcyan"
[406] "lightcyan1" "lightcyan2" "lightcyan3"
[409] "lightcyan4" "lightgoldenrod" "lightgoldenrod1"
[412] "lightgoldenrod2" "lightgoldenrod3" "lightgoldenrod4"
[415] "lightgoldenrodyellow" "lightgray" "lightgreen"
[418] "lightgrey" "lightpink" "lightpink1"
[421] "lightpink2" "lightpink3" "lightpink4"
[424] "lightsalmon" "lightsalmon1" "lightsalmon2"
[427] "lightsalmon3" "lightsalmon4" "lightseagreen"
[430] "lightskyblue" "lightskyblue1" "lightskyblue2"
[433] "lightskyblue3" "lightskyblue4" "lightslateblue"
[436] "lightslategray" "lightslategrey" "lightsteelblue"
[439] "lightsteelblue1" "lightsteelblue2" "lightsteelblue3"
[442] "lightsteelblue4" "lightyellow" "lightyellow1"
[445] "lightyellow2" "lightyellow3" "lightyellow4"
[448] "limegreen" "linen" "magenta"
[451] "magenta1" "magenta2" "magenta3"
[454] "magenta4" "maroon" "maroon1"
[457] "maroon2" "maroon3" "maroon4"
[460] "mediumaquamarine" "mediumblue" "mediumorchid"
[463] "mediumorchid1" "mediumorchid2" "mediumorchid3"
[466] "mediumorchid4" "mediumpurple" "mediumpurple1"
[469] "mediumpurple2" "mediumpurple3" "mediumpurple4"
[472] "mediumseagreen" "mediumslateblue" "mediumspringgreen"
[475] "mediumturquoise" "mediumvioletred" "midnightblue"
[478] "mintcream" "mistyrose" "mistyrose1"
[481] "mistyrose2" "mistyrose3" "mistyrose4"
[484] "moccasin" "navajowhite" "navajowhite1"
[487] "navajowhite2" "navajowhite3" "navajowhite4"
[490] "navy" "navyblue" "oldlace"
[493] "olivedrab" "olivedrab1" "olivedrab2"
[496] "olivedrab3" "olivedrab4" "orange"
[499] "orange1" "orange2" "orange3"
[502] "orange4" "orangered" "orangered1"
[505] "orangered2" "orangered3" "orangered4"
[508] "orchid" "orchid1" "orchid2"
[511] "orchid3" "orchid4" "palegoldenrod"
[514] "palegreen" "palegreen1" "palegreen2"
[517] "palegreen3" "palegreen4" "paleturquoise"
[520] "paleturquoise1" "paleturquoise2" "paleturquoise3"
[523] "paleturquoise4" "palevioletred" "palevioletred1"
[526] "palevioletred2" "palevioletred3" "palevioletred4"
[529] "papayawhip" "peachpuff" "peachpuff1"
[532] "peachpuff2" "peachpuff3" "peachpuff4"
[535] "peru" "pink" "pink1"
[538] "pink2" "pink3" "pink4"
[541] "plum" "plum1" "plum2"
[544] "plum3" "plum4" "powderblue"
[547] "purple" "purple1" "purple2"
[550] "purple3" "purple4" "red"
[553] "red1" "red2" "red3"
[556] "red4" "rosybrown" "rosybrown1"
[559] "rosybrown2" "rosybrown3" "rosybrown4"
[562] "royalblue" "royalblue1" "royalblue2"
[565] "royalblue3" "royalblue4" "saddlebrown"
[568] "salmon" "salmon1" "salmon2"
[571] "salmon3" "salmon4" "sandybrown"
[574] "seagreen" "seagreen1" "seagreen2"
[577] "seagreen3" "seagreen4" "seashell"
[580] "seashell1" "seashell2" "seashell3"
[583] "seashell4" "sienna" "sienna1"
[586] "sienna2" "sienna3" "sienna4"
[589] "skyblue" "skyblue1" "skyblue2"
[592] "skyblue3" "skyblue4" "slateblue"
[595] "slateblue1" "slateblue2" "slateblue3"
[598] "slateblue4" "slategray" "slategray1"
[601] "slategray2" "slategray3" "slategray4"
[604] "slategrey" "snow" "snow1"
[607] "snow2" "snow3" "snow4"
[610] "springgreen" "springgreen1" "springgreen2"
[613] "springgreen3" "springgreen4" "steelblue"
[616] "steelblue1" "steelblue2" "steelblue3"
[619] "steelblue4" "tan" "tan1"
[622] "tan2" "tan3" "tan4"
[625] "thistle" "thistle1" "thistle2"
[628] "thistle3" "thistle4" "tomato"
[631] "tomato1" "tomato2" "tomato3"
[634] "tomato4" "turquoise" "turquoise1"
[637] "turquoise2" "turquoise3" "turquoise4"
[640] "violet" "violetred" "violetred1"
[643] "violetred2" "violetred3" "violetred4"
[646] "wheat" "wheat1" "wheat2"
[649] "wheat3" "wheat4" "whitesmoke"
[652] "yellow" "yellow1" "yellow2"
[655] "yellow3" "yellow4" "yellowgreen"
[1] "#1B9E77" "#D95F02" "#7570B3" "#E7298A" "#66A61E" "#E6AB02" "#A6761D"
[8] "#666666"
# Collapses red-green or green-blue color distinctions
# to approximate the effect of the three forms of
# dichromacy: protanopia and
# deuteranopia (red-green color blindness), and
# tritanopia (green-blue color blindness).
dichromat::colorschemes
$BrowntoBlue.10
[1] "#663000" "#996136" "#CC9B7A" "#D9AF98" "#F2DACE" "#CCFDFF" "#99F8FF"
[8] "#66F0FF" "#33E4FF" "#00AACC"
$BrowntoBlue.12
[1] "#331A00" "#663000" "#996136" "#CC9B7A" "#D9AF98" "#F2DACE" "#CCFDFF"
[8] "#99F8FF" "#66F0FF" "#33E4FF" "#00AACC" "#007A99"
$BluetoDarkOrange.12
[1] "#1F8F99" "#52C4CC" "#99FAFF" "#B2FCFF" "#CCFEFF" "#E6FFFF" "#FFE6CC"
[8] "#FFCA99" "#FFAD66" "#FF8F33" "#CC5800" "#994000"
$BluetoDarkOrange.18
[1] "#006666" "#009999" "#00CCCC" "#00FFFF" "#33FFFF" "#66FFFF" "#99FFFF"
[8] "#B2FFFF" "#CCFFFF" "#E6FFFF" "#FFE6CC" "#FFCA99" "#FFAD66" "#FF8F33"
[15] "#FF6E00" "#CC5500" "#993D00" "#662700"
$DarkRedtoBlue.12
[1] "#2A0BD9" "#264EFF" "#40A1FF" "#73DAFF" "#ABF8FF" "#E0FFFF" "#FFFFBF"
[8] "#FFE099" "#FFAD73" "#F76E5E" "#D92632" "#A60021"
$DarkRedtoBlue.18
[1] "#2400D9" "#191DF7" "#2957FF" "#3D87FF" "#57B0FF" "#75D3FF" "#99EBFF"
[8] "#BDF9FF" "#EBFFFF" "#FFFFEB" "#FFF2BD" "#FFD699" "#FFAC75" "#FF7857"
[15] "#FF3D3D" "#F72836" "#D91630" "#A60021"
$BluetoGreen.14
[1] "#0000FF" "#3333FF" "#6666FF" "#9999FF" "#B2B2FF" "#CCCCFF" "#E6E6FF"
[8] "#E6FFE6" "#CCFFCC" "#B2FFB2" "#99FF99" "#66FF66" "#33FF33" "#00FF00"
$BluetoGray.8
[1] "#0099CC" "#66E6FF" "#99FFFF" "#CCFFFF" "#E6E6E6" "#999999" "#666666"
[8] "#333333"
$BluetoOrangeRed.14
[1] "#085AFF" "#3377FF" "#5991FF" "#8CB2FF" "#BFD4FF" "#E6EEFF" "#F7FAFF"
[8] "#FFFFCC" "#FFFF99" "#FFFF00" "#FFCC00" "#FF9900" "#FF6600" "#FF0000"
$BluetoOrange.10
[1] "#0055FF" "#3399FF" "#66CCFF" "#99EEFF" "#CCFFFF" "#FFFFCC" "#FFEE99"
[8] "#FFCC66" "#FF9933" "#FF5500"
$BluetoOrange.12
[1] "#002BFF" "#1A66FF" "#3399FF" "#66CCFF" "#99EEFF" "#CCFFFF" "#FFFFCC"
[8] "#FFEE99" "#FFCC66" "#FF9933" "#FF661A" "#FF2B00"
$BluetoOrange.8
[1] "#0080FF" "#4CC4FF" "#99EEFF" "#CCFFFF" "#FFFFCC" "#FFEE99" "#FFC44C"
[8] "#FF8000"
$LightBluetoDarkBlue.10
[1] "#E6FFFF" "#CCFBFF" "#B2F2FF" "#99E6FF" "#80D4FF" "#66BFFF" "#4CA6FF"
[8] "#3388FF" "#1A66FF" "#0040FF"
$LightBluetoDarkBlue.7
[1] "#FFFFFF" "#CCFDFF" "#99F8FF" "#66F0FF" "#33E4FF" "#00AACC" "#007A99"
$Categorical.12
[1] "#FFBF80" "#FF8000" "#FFFF99" "#FFFF33" "#B2FF8C" "#33FF00" "#A6EDFF"
[8] "#1AB2FF" "#CCBFFF" "#664CFF" "#FF99BF" "#E61A33"
$GreentoMagenta.16
[1] "#005100" "#008600" "#00BC00" "#00F100" "#51FF51" "#86FF86" "#BCFFBC"
[8] "#FFFFFF" "#FFF1FF" "#FFBCFF" "#FF86FF" "#FF51FF" "#F100F1" "#BC00BC"
[15] "#860086" "#510051"
$SteppedSequential.5
[1] "#990F0F" "#B22D2D" "#CC5252" "#E67E7E" "#FFB2B2" "#99700F" "#B28B2D"
[8] "#CCA852" "#E6C77E" "#FFE8B2" "#1F990F" "#3CB22D" "#60CC52" "#8AE67E"
[15] "#BCFFB2" "#710F99" "#8B2DB2" "#A852CC" "#C77EE6" "#E9B2FF" "#990F20"
[22] "#B22D3C" "#CC5260" "#E67E8A" "#FFB2BC"
## from example(pie)
par(mfrow = c(2, 2))
pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
names(pie.sales) <- c("Blueberry", "Cherry",
"Apple", "Boston Cream", "Other", "Vanilla Cream")
pie(pie.sales, # default colors
col = c("white", "lightblue", "mistyrose", "lightcyan", "lavender", "cornsilk"))
pie(pie.sales,
col = c("purple", "violetred1", "green3", "cornsilk", "cyan", "white"))
pie(pie.sales, col = dichromat::dichromat(
c("white", "lightblue", "mistyrose", "lightcyan", "lavender", "cornsilk")))
pie(pie.sales, col = dichromat::dichromat(
c("purple", "violetred1", "green3", "cornsilk", "cyan", "white")))
## standard color schemes
pie(rep(1,10), col = heat.colors(10))
pie(rep(1,10), col = dichromat::dichromat(heat.colors(10)))
pie(rep(1,8), col = palette())
pie(rep(1,8), col = dichromat::dichromat(palette()))
pie(rep(1,15), col = topo.colors(15))
pie(rep(1,15), col = dichromat::dichromat(topo.colors(15)))
pie(rep(1,15), col = terrain.colors(15))
pie(rep(1,15), col = dichromat::dichromat(terrain.colors(15)))
pie(rep(1,15), col = cm.colors(15))
pie(rep(1,15), col = dichromat::dichromat(cm.colors(15)))
## color ramp schemes
bluescale <- colorRampPalette(c("#FFFFCC", "#C7E9B4", "#7FCDBB",
"#40B6C4", "#2C7FB8" , "#253494"))
redgreen <- colorRampPalette(c("red", "green3"))
pie(rep(1,15), col = bluescale(15))
pie(rep(1,15), col = dichromat::dichromat(bluescale(15)))
par(mfrow = c(2, 4))
x <- matrix(rnorm(10 * 10), 10)
image(1:10, 1:10, x, col = bluescale(10), main = "blue-yellow scale")
image(1:10, 1:10, x, col = dichromat::dichromat(bluescale(10), "deutan"), main = "deutan")
image(1:10, 1:10, x, col = dichromat::dichromat(bluescale(10), "protan"), main = "protan")
image(1:10, 1:10, x, col = dichromat::dichromat(bluescale(10), "tritan"), main = "tritan")
image(1:10, 1:10, x, col = redgreen(10), main = "red-green scale")
image(1:10, 1:10, x, col = dichromat::dichromat(redgreen(10), "deutan"), main = "deutan")
image(1:10, 1:10, x, col = dichromat::dichromat(redgreen(10), "protan"), main = "protan")
image(1:10, 1:10, x, col = dichromat::dichromat(redgreen(10), "tritan"), main = "tritan")