Matematyka_Bayes/charts.R

55 lines
1.6 KiB
R
Raw Permalink Normal View History

2021-06-01 17:19:33 +02:00
library(highcharter)
library(tidyr)
library(plotly)
library(dplyr)
2021-05-31 22:09:09 +02:00
basedf<-read.csv("dev/matma_bayes/heart.csv", header = TRUE)
siha<-read.csv('dev/matma_bayes/sex_if_heart_attack.csv')
df2<-read.csv('dev/matma_bayes/age_sex_heart_attack.csv')
2021-06-01 17:19:33 +02:00
chol<-read.csv('dev/matma_bayes/chol_sex_heart_attack.csv')
2021-05-31 22:09:09 +02:00
basedf$sex[basedf$sex==1]<-'Man'
basedf$sex[basedf$sex==0]<-'Woman'
df2$sex[df2$sex==1]<-'Man'
df2$sex[df2$sex==0]<-'Woman'
2021-06-01 17:19:33 +02:00
chol$sex[chol$sex==1]<-'Man'
chol$sex[chol$sex==0]<-'Woman'
2021-05-31 22:09:09 +02:00
df2$x<-paste(df2$sex,df2$age)
2021-06-01 17:19:33 +02:00
2021-05-31 22:09:09 +02:00
basedf%>%
count(sex)%>% arrange(n)%>%
hchart(type = "pie", hcaes(x=sex, y = n, color = n), name="Quantity") %>%
hc_title(text="<b>Sex in dataset</b>")
siha%>%
2021-06-01 17:19:33 +02:00
hchart(type = "pie", hcaes(x=sex, y = Probability, color = Probability), name='Probability') %>%
2021-05-31 22:09:09 +02:00
hc_title(text="<b>Sex if heart attack</b>")
2021-06-01 17:19:33 +02:00
2021-05-31 22:09:09 +02:00
df2%>%
hchart('column', hcaes(x=x, y=heart.attack, group=age))%>%
hc_plotOptions(column = list(stacking = "normal"))%>%
hc_xAxis(title=list(text='Age'))%>%
hc_yAxis(title=list(text='Probability'))%>%
2021-05-31 22:15:53 +02:00
hc_legend(enabled=F)%>%
hc_title(text="<b>Probability of heart attack for sex and age group</b>")
2021-06-01 17:19:33 +02:00
chol %>%
drop_na(heart.attack)%>%
plot_ly(x = ~heart.attack,
y = ~sex,
type = 'bar',
orientation = 'h',
color = ~chol,
colors ='Spectral',
hoverinfo = 'text',
text = ~paste('Probability:', heart.attack, '<br> Interval:', chol),
xaxis=list(categoryorder='total descending')) %>%
layout(title = 'Chol/probability',
xaxis = list(title = "Probability"),
yaxis = list(title = "Cholesterol"))