This data set CardioGoodFitness.csv is for customers of the treadmill product(s) of a retail store called Cardio Good Fitness. It contains the following variables Product, Age, Gender, Education, MaritalStatus, Usage, Fitness, Income, and Miles. Draw horizontal barplots of MaritalStatus (on y-axis) and Income (on x-axis) with gender distinction.
时间: 2023-12-03 11:45:49 浏览: 117
Sure, here's the code to create the barplot using the ggplot2 library in R:
```{r}
library(ggplot2)
# Load the data
cardio <- read.csv("CardioGoodFitness.csv")
# Create the barplot
ggplot(cardio, aes(x = Income, y = MaritalStatus, fill = Gender)) +
geom_bar(stat = "identity", position = "dodge") +
labs(x = "Income", y = "Marital Status", fill = "Gender") +
theme_bw()
```
This code will produce a horizontal barplot with income on the x-axis and marital status on the y-axis, with bars distinguished by gender. The `fill` parameter is used to distinguish between male and female customers. The `position` parameter is set to "dodge" to display the bars side by side.
阅读全文