R中的图表不显示数据 [英] Chart in R not displaying data
本文介绍了R中的图表不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数据框:
vector_builtin vector_loop vector_recursive
1 0.00 0.10 0.34
2 0.00 0.10 0.36
3 0.00 0.08 0.36
4 0.00 0.11 0.34
5 0.00 0.11 0.36
我想在折线图中显示三列。
我已将ggplot2导入到R中,并且该图表显示时没有数据或折线。
代码:
库(ggplot2)
索引<-row.names(df.new)
ggplot(df.new,aes(x = vector_recursive,y = indexes))
图表输出
在折线图中显示三个系列的图表。
I have the following data frame:
vector_builtin vector_loop vector_recursive
1 0.00 0.10 0.34
2 0.00 0.10 0.36
3 0.00 0.08 0.36
4 0.00 0.11 0.34
5 0.00 0.11 0.36
I want to display the three columns in a line chart.
I have imported ggplot2 into R and the chart is displaying without data or lines in it.
Code:
library(ggplot2)
indexes <- row.names(df.new)
ggplot(df.new, aes(x=vector_recursive, y=indexes))
Chart output
Output I want A chart showing the three series in a line chart.
解决方案
A very basic example using ggplot2
and df from OP can be:
df <- read.table(text = "time vector_builtin vector_loop vector_recursive
1 0.00 0.10 0.34
2 0.00 0.10 0.36
3 0.00 0.08 0.36
4 0.00 0.11 0.34
5 0.00 0.11 0.36", header = T, stringsAsFactors = F)
p <- ggplot() +
geom_line(aes(time, vector_builtin, colour = "red"), data = df) +
geom_line(aes(time, vector_loop, colour = "green"), data = df) +
geom_line(aes(time, vector_recursive, colour = "blue"), data = df) +
labs(x="Time(s)", y="Value") + # Labels for axis
scale_color_manual("Data Types", values=c(red="red",green="green",blue="blue"),
labels=c("vector_builtin", "vector_loop", "vector_recursive" ))
print(p)
这篇关于R中的图表不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文