为什么GGPLOT在安装后在R中不适用于我?

发布于 2025-02-12 17:58:21 字数 4729 浏览 0 评论 0原文

我的工作笔记本电脑上安装了RSTUDIO版本3.5.0。我下载了GGPLOT并从Cran中绘制,并使用软件包 - >在R中的本地文件中安装软件包。然后我打开rstudio并运行多个不同的代码以查看它们是否有效。这是我尝试运行的一个:

df <- data.frame(dose=c("D0.5", "D1", "D2"),
                 len=c(4.2, 10, 29.5))
head(df)
library(ggplot2)
# Basic barplot
p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
p

# Horizontal bar plot
p + coord_flip()

但是我会遇到以下错误:

> library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
 number of columns of matrices must match (see arg 2)
In addition: Warning message:
package ‘ggplot2’ was built under R version 4.3.0 
> # Basic barplot
> p<-ggplot(data=df, aes(x=dose, y=len)) +
+   geom_bar(stat="identity")
Error in ggplot(data = df, aes(x = dose, y = len)) : 
  could not find function "ggplot"
> p
Error: object 'p' not found
> 
> # Horizontal bar plot
> p + coord_flip()
Error: object 'p' not found

有人知道为什么我会得到这种情况吗?我以为我拥有的R版本比软件包还要古老,但是我在网上读到限制很小。

只需注意,当我尝试通过R Studio安装GGPLOT时,通过键入以下命令install.packages(“ ggplot2”)时,我会收到以下错误:

> install.packages("ggplot2")
Installing package into ‘\\lsjsh-mp-ns1/user$/H/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "\\lsjsh-mp-ns1/user$/H/R/win-library/3.5"' is not writable
also installing the dependencies ‘lifecycle’, ‘glue’, ‘scales’, ‘withr’


  There are binary versions available but the source versions are later:
          binary source needs_compilation
lifecycle  0.2.0  1.0.1             FALSE
glue       1.4.0  1.6.2              TRUE
scales     1.1.0  1.2.0             FALSE
withr      2.2.0  2.5.0             FALSE
ggplot2    3.3.0  3.3.6             FALSE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/glue_1.4.0.zip'
Content type 'application/zip' length 157284 bytes (153 KB)
downloaded 153 KB

package ‘glue’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  cannot remove prior installation of package ‘glue’

The downloaded binary packages are in
    C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages
installing the source packages ‘lifecycle’, ‘scales’, ‘withr’, ‘ggplot2’

trying URL 'https://cran.rstudio.com/src/contrib/lifecycle_1.0.1.tar.gz'
Content type 'application/x-gzip' length 99716 bytes (97 KB)
downloaded 97 KB

trying URL 'https://cran.rstudio.com/src/contrib/scales_1.2.0.tar.gz'
Content type 'application/x-gzip' length 270188 bytes (263 KB)
downloaded 263 KB

trying URL 'https://cran.rstudio.com/src/contrib/withr_2.5.0.tar.gz'
Content type 'application/x-gzip' length 102089 bytes (99 KB)
downloaded 99 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_3.3.6.tar.gz'
Content type 'application/x-gzip' length 3061989 bytes (2.9 MB)
downloaded 2.9 MB

'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-lifecycle'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘lifecycle’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-withr'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘withr’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-scales'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘scales’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-ggplot2'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
    ‘C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages’

I have R version 3.5.0 and RStudio installed on my work laptop. I downloaded ggplot and plotly from CRAN and installed it using Packages -> install package(s) from local file(s) in R. I then opened RStudio and ran multiple different codes to see if they work. Here is is one I tried running:

df <- data.frame(dose=c("D0.5", "D1", "D2"),
                 len=c(4.2, 10, 29.5))
head(df)
library(ggplot2)
# Basic barplot
p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
p

# Horizontal bar plot
p + coord_flip()

But I get the following errors:

> library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
 number of columns of matrices must match (see arg 2)
In addition: Warning message:
package ‘ggplot2’ was built under R version 4.3.0 
> # Basic barplot
> p<-ggplot(data=df, aes(x=dose, y=len)) +
+   geom_bar(stat="identity")
Error in ggplot(data = df, aes(x = dose, y = len)) : 
  could not find function "ggplot"
> p
Error: object 'p' not found
> 
> # Horizontal bar plot
> p + coord_flip()
Error: object 'p' not found

Does anyone know why I am getting this could be happening?. I was thinking that the R version I have is older than the packages but I read somewhere online that the limitations are minuscule.

Just a note, when I try to install ggplot via R studio by typing the following command install.packages("ggplot2"), I get the following error:

> install.packages("ggplot2")
Installing package into ‘\\lsjsh-mp-ns1/user$/H/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "\\lsjsh-mp-ns1/user$/H/R/win-library/3.5"' is not writable
also installing the dependencies ‘lifecycle’, ‘glue’, ‘scales’, ‘withr’


  There are binary versions available but the source versions are later:
          binary source needs_compilation
lifecycle  0.2.0  1.0.1             FALSE
glue       1.4.0  1.6.2              TRUE
scales     1.1.0  1.2.0             FALSE
withr      2.2.0  2.5.0             FALSE
ggplot2    3.3.0  3.3.6             FALSE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/glue_1.4.0.zip'
Content type 'application/zip' length 157284 bytes (153 KB)
downloaded 153 KB

package ‘glue’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  cannot remove prior installation of package ‘glue’

The downloaded binary packages are in
    C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages
installing the source packages ‘lifecycle’, ‘scales’, ‘withr’, ‘ggplot2’

trying URL 'https://cran.rstudio.com/src/contrib/lifecycle_1.0.1.tar.gz'
Content type 'application/x-gzip' length 99716 bytes (97 KB)
downloaded 97 KB

trying URL 'https://cran.rstudio.com/src/contrib/scales_1.2.0.tar.gz'
Content type 'application/x-gzip' length 270188 bytes (263 KB)
downloaded 263 KB

trying URL 'https://cran.rstudio.com/src/contrib/withr_2.5.0.tar.gz'
Content type 'application/x-gzip' length 102089 bytes (99 KB)
downloaded 99 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_3.3.6.tar.gz'
Content type 'application/x-gzip' length 3061989 bytes (2.9 MB)
downloaded 2.9 MB

'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-lifecycle'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘lifecycle’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-withr'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘withr’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-scales'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘scales’ had non-zero exit status
'\\lsjsh-mp-ns1\user$\H'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
ERROR: failed to lock directory '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5' for modifying
Try removing '\\lsjsh-mp-ns1/user$/H/R/win-library/3.5/00LOCK-ggplot2'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
    ‘C:\Users\H\AppData\Local\Temp\Rtmp2NJuUu\downloaded_packages’

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文