简体   繁体   English

在R中绘制数据框

[英]plot data frame in R

I want to plot some data in R. However, when I try to plot my dataframe "bef_ads", a large number of plots are shown together. 我想在R中绘制一些数据。但是,当我尝试绘制数据框“ bef_ads”时,会同时显示大量图表。 I just want to get the list inside the data frame and make a normal plot. 我只想获取数据框内的列表并进行法线绘制。

Thanks! 谢谢!

dput(bef_ads)
structure(list(V1 = 56660L, V2 = 60616L, V3 = 85913L, V4 = 70709L), 
 .Names = c("V1","V2", "V3", "V4"), row.names = c(NA, -1L), class = "data.frame")

The problem is that your data is in different columns of a data frame with 1 row. 问题是您的数据位于具有1行的数据框的不同列中。 When you use plot(...) on this, it treats each column as a different dataset (with just one point, in your case). 在此上使用plot(...)时,它将每一列视为不同的数据集(在您的情况下,只有一个点)。 This is why you are getting all those plots. 这就是为什么要获得所有这些图的原因。

So you could transpose the dataframe (to one with one column and 4 rows), and plot that: 因此,您可以转置数据框(到一列四行的数据框),并进行绘制:

plot(t(bef_ads),type="b")

Or you could "unlist" the data frame as suggested in a comment. 或者,您也可以按照注释中的建议“取消列出”数据框。 This basically converts the data frame to a vector and plots that. 基本上,这会将数据帧转换为矢量并将其绘制出来。

plot(unlist(bef_ads),type="b")

For a barplot: 对于条形图:

barplot(unlist(bef_ads))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM