data<-c( ID Math History Chem Group 1 S1 98 92 95 J 2 S2 96 90 93 S 3 S3 99 93 96 J 4 S4 100 94 97 J 5 S5 99 93 96 S 6 S6 95 89 92 S 7 S7 93 87 90 J 8 S8 94 88 91 S 9 S9 99 93 96 J 10 S10 97 91 94 J 11 S11 95 89 92 S 12 S12 92 86 89 S 13 S13 91 85 88 J 14 S14 89 83 86 S 15 S15 93 87 90 J 16 S16 99 93 96 S 17 S17 92 86 89 J 18 S18 91 85 88 S 19 S19 99 93 85 J),plot 'Math', 'History' and 'Chem' scores based on 'Group'
时间: 2023-12-30 10:05:51 浏览: 205
To plot the 'Math', 'History', and 'Chem' scores based on 'Group', we can use the ggplot2 package in R. Here is the R code to do that:
```R
library(ggplot2)
# Convert data to data frame
df <- data.frame(ID = data[seq(1,length(data),5)],
Math = data[seq(2,length(data),5)],
History = data[seq(3,length(data),5)],
Chem = data[seq(4,length(data),5)],
Group = data[seq(5,length(data),5)])
# Plot using ggplot2
ggplot(df, aes(x = Group)) +
geom_boxplot(aes(y = Math, fill = Group), alpha = 0.5) +
geom_boxplot(aes(y = History, fill = Group), alpha = 0.5) +
geom_boxplot(aes(y = Chem, fill = Group), alpha = 0.5) +
labs(x = "Group", y = "Score") +
scale_fill_manual(values = c("blue", "red")) +
theme_minimal()
```
This will create a boxplot for each score ('Math', 'History', and 'Chem') with 'Group' on the X-axis. The blue boxplots represent the 'J' group and the red boxplots represent the 'S' group. The alpha parameter controls the transparency of the boxplots. You can adjust this value to your preference.
阅读全文