0

I have a table that contains the account balance and marital status of an individual (married, unmarried, divorced). How do I use ggplot() to plot the balance of each marital status at once?

My current method is not very efficient:

married <- subset(bank[,c("marital","balance")], marital == "married")
4

1 回答 1

1

您可以更具体地了解您的问题。您希望如何显示您的数据?无论如何,这里有几种可能性。希望您可以将其中之一用于您的目的。

# load packages
pkgs2load <- c("data.table", "ggplot2", "data.table")
sapply(pkgs2load, require, character.only=TRUE)
# generate sample data
N <- 1e4
dt <- data.table(balance = runif(N, 0, 1e6),
                 status = sample(c("married", "unmarried", "divorced"), N, replace=TRUE))
# plots
ggplot(dt, aes(status, balance)) + stat_summary(fun.data = "mean_cl_boot")
ggplot(dt, aes(status, balance)) + geom_jitter()
ggplot(dt, aes(factor(0), balance, color=status)) + geom_jitter() + 
  scale_x_discrete(name="", breaks=NULL)
于 2013-11-11T14:30:46.313 回答