由于没有给出数据 ex1221new,所以我创建了一个虚拟数据并将其添加到数据框中。此外,被问到的问题在代码中几乎没有变化,例如 ggplot 包已弃用
"scale_area()" and nows uses scale_size_area()
"opts()" has changed to theme()
在我的回答中,我已将绘图存储在 mygraph 变量中,然后我使用了
mygraph$labels$x="Discharge of materials" #changes x axis title
mygraph$labels$y="Area Affected" # changes y axis title
工作完成了。以下是完整的答案。
install.packages("Sleuth2")
library(Sleuth2)
library(ggplot2)
ex1221new<-data.frame(Discharge<-c(100:109),Area<-c(120:129),NO3<-seq(2,5,length.out = 10))
discharge<-ex1221new$Discharge
area<-ex1221new$Area
nitrogen<-ex1221new$NO3
p <- ggplot(ex1221new, aes(discharge, area), main="Point")
mygraph<-p + geom_point(aes(size= nitrogen)) +
scale_size_area() + ggtitle("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)")+
theme(
plot.title = element_text(color="Blue", size=30, hjust = 0.5),
# change the styling of both the axis simultaneously from this-
axis.title = element_text(color = "Green", size = 20, family="Courier",)
# you can change the axis title from the code below
mygraph$labels$x="Discharge of materials" #changes x axis title
mygraph$labels$y="Area Affected" # changes y axis title
mygraph
此外,您可以使用上面使用的相同公式更改标签标题 -
mygraph$labels$size= "N2" #size contains the nitrogen level