首页 > 解决方案 > 你如何在 R 中改变你的情节的起点?

问题描述

我想将图表的起点(在 x 轴和 y 轴上)设置为零。我使用了xlim()andylim()功能无济于事。我在下面附上了我的代码。

setwd ("D:/Rcode/Assignment_2") #setting up the working directory
LightGrowth1 <- read.csv ("LightGrowth-1.csv") #reading the file and attaching it to a dataframe
Light <- LightGrowth1$light #attach our light values to a vector in R
Growth <- LightGrowth1$growth #attach our growth values to a vector in R
Labels <- c("Light", "Growth") #create a vector using the labels 
plot (Light, Growth, xlab = "Amount of Light (units)", ylab = "Plant Growth (units)", 
      pch = 16, col= "firebrick", xlim = c(0, max (Light)), ylim = c (0, max (Growth)),
      main = "Plant Growth vs Amount of Light"
       
        )

这是我的情节目前的样子: 阴谋

标签: rscatter-plot

解决方案


你的坐标轴确实从 0 开始,xlim并且ylim是你需要改变它的地方。

我认为您指的是轴和绘图之间的间距。有两个额外的参数可以让你改变它,xaxsyaxs.

plot (x, y, xlim=c(0,10), ylim=c(0,10),
      xaxs="i", yaxs="i") 

这应该可以解决问题

有关更多信息,请参阅par帮助。


推荐阅读