Primeiro Gráfico
library(ggplot2)
db <- read.csv('db.csv')
head(db)
## X autoN autoE autoO autoC autoA obseN obseE obseO obseC obseA
## 1 1 24 29 44 54 65 19 38 49 48 60
## 2 2 18 28 38 56 75 31 32 43 61 66
## 3 3 30 40 41 51 55 19 48 33 54 57
## 4 4 38 37 42 35 48 31 38 45 45 51
## 5 5 16 36 41 69 69 15 34 40 68 69
## 6 6 25 28 29 54 62 15 38 41 60 58
# Parâmetros
dens <- density(db$autoN)
df <- data.frame(x=dens$x, y=dens$y)
probs <- c(0, 0.25, 0.5, 0.75, 1)
quantiles <- quantile(db$autoN, prob=probs)
df$quant <- factor(findInterval(df$x,quantiles))
head(df)
## x y quant
## 1 7.973458 3.839389e-05 0
## 2 8.055754 4.231359e-05 0
## 3 8.138049 4.665895e-05 0
## 4 8.220345 5.129582e-05 0
## 5 8.302641 5.640052e-05 0
## 6 8.384936 6.202891e-05 0
quantiles
## 0% 25% 50% 75% 100%
## 16.00 23.25 29.00 33.00 42.00
# Gráfico
ggplot(df, aes(x,y))+
geom_line()+
geom_ribbon(aes(ymin=0, ymax=y, fill=quant))+
scale_x_continuous(breaks=quantiles)+
scale_fill_brewer(guide="none") +
geom_vline(xintercept = db$autoN[1])

library(plotly, dplyr)
dfSDS <- data.frame(
interesses = c(
'Realista',
'Investigativo',
'Artístico',
'Social',
'Empreendedor',
'Convencional'
),
percentis = c(
15,
25,
55,
33,
87,
65
)
)
# Adicione essa linha se quiser manter as barras na mesma ordem.
dfSDS$interesses <- factor(dfSDS$interesses, levels = dfSDS$interesses)
sepPerc <- dfSDS$percentis[order(dfSDS$percentis)]
dfSDS$color <- ifelse(dfSDS$percentis >= sepPerc[4], 'rgb(29, 184, 255)', 'rgb(128, 128, 128)')
line <- list(
type = 'line',
line = list(
color = "black",
dash = 'dash'),
xref = "x",
yref = "y"
)
lines <- list()
for (i in c(25, 50, 75)) {
line[["x0"]] <- -0.5
line[["x1"]] <- 5.5
line[["y0"]] <- i
line[["y1"]] <- i
line[["text"]] <- "teste"
lines <- c(lines, list(line))
}
plot_ly(
dfSDS,
x = ~interesses,
y = ~percentis,
type = 'bar',
hoverinfo = "text",
text = paste(dfSDS$interesses, ": ",dfSDS$percentis, sep = ''),
marker = list(
color = ~color,
line = list(
color = ~color,
width = 1.5)
)
) %>%
layout(
title = "RIASEC",
xaxis = list(title = ""),
yaxis = list(title = ""),
shapes=lines,
annotations = list(
list(
text = "Baixo", x = 6, y = 25,showarrow=FALSE
),
list(
text = "Médio", x = 6, y = 50,showarrow=FALSE
),
list(
text = "Alto", x = 6, y = 75,showarrow=FALSE
)
)
) %>%
config(displayModeBar = F)