Run the following code in your R console. states <- data.frame(state.region, state.x77) Draw a Kernel density of per capita income
时间: 2023-07-15 22:11:01 浏览: 114
plotMElm:R包,用于绘制从线性模型估计的相互作用的边际效应
Sure! Here's how you can do it:
```R
# Load the necessary library
library(ggplot2)
# Create a data frame with state region and per capita income
states <- data.frame(state.region, state.x77)
# Rename the variables
names(states) <- c("region", "per_capita_income")
# Draw a kernel density plot of per capita income
ggplot(states, aes(x = per_capita_income)) +
geom_density(fill = "blue", alpha = 0.5) +
ggtitle("Kernel density of per capita income")
```
This code will create a kernel density plot of per capita income using the `ggplot2` library in R. The plot will have a blue fill and an alpha value of 0.5 to make it more visually appealing.
阅读全文