在R中通过ggplot绘制直方图

我正在尝试使用ggplot绘制血压与结果的直方图,但R中给出的图未遵循数据文件中提供的数据。这是数据文件的链接:https://www.kaggle.com/kandij/diabetes-dataset

dataset=read.csv(file.choose(),header=T)
attach(dataset)
View(dataset)
str(dataset)
summary(dataset)
Bloodpressure_Freq <- frequency(dataset$BloodPressure)
Positive_or_Negative <- as.factor(dataset$Outcome)

ggplot(data = dataset,aes(x = BloodPressure,Bloodpressure_Freq,fill =Positive_or_Negative)) + 
geom_col()+
labs(title = "Histogram for Age",x = "Age",y = "Count") +
theme(plot.title = element_text(hjust = 0.5))

在R中通过ggplot绘制直方图

adsli 回答:在R中通过ggplot绘制直方图

这是您要找的吗?

library(tidyverse)

dataset %>% 
  ggplot(aes(x=BloodPressure,fill = as.factor(Outcome))) + 
  geom_histogram() + 
  facet_wrap(~Outcome)

enter image description here

您可以使用theme()更改图例标题。

本文链接:https://www.f2er.com/3098326.html

大家都在问