在R中使用gvisTimeline

时间:2015-08-05 22:29:02

标签: r csv dataframe google-visualization googlevis

我不熟悉在R中使用GoogleVis库,我有一个CSV文件,我已将其转换为data.frame,因为我需要将data.frame提供给gvisTimeline。你能告诉我如何修复参数吗?

prob <- read.csv("_slash_probability.csv", header = TRUE, sep = ",")
plot(gvisTimeline(prob, barlabel="timestamp", rowlabel="fruit",
                  options=list(width=600, height=350))
)

以下是我得到的错误:

Invalid data table format: must have 3 or 4 data columns.×

enter image description here

以下是我的csv文件的样子:

rosbagTimestamp,data
1438293895271171569,blueberry 0.0939634317574;
1438293895303195547,blueberry 0.0846330225841;
1438293895304291013,blueberry 0.0828378077875;
1438293895337791976,blueberry 0.0797700384253;
1438293895401420350,blueberry 0.0759388571186;
1438293895472735323,blueberry 0.0750429342259;
1438293895476007383,blueberry 0.0750213831086;
1438293895507707571,blueberry 0.075791014733;
1438293895573689503,blueberry 0.0776209483645;
1438293895637463777,blueberry 0.0834959971174;
1438293895641481231,blueberry 0.0879266074843;
1438293895656845822,blueberry 0.0904240066394;
1438293895771521924,blueberry 0.0883910759335;apple 0.0826913130923;
1438293895841645544,blueberry 0.0883910759335;apple 0.0774326788207;
1438293896011836483,strawberry 0.0793898589924;blueberry 0.0883910759335;apple 0.0882327474566;

在最后一个中说它说机器人看到每个水果的概率是多少。

更新: 我用了这段代码:

prob <- read.csv("_slash_signal.csv", header = TRUE, sep = ",")
plot(gvisTimeline(prob, barlabel="rosbagTimestamp", rowlabel="data",
                  options=list(width=600, height=350))
)

这个csv:

rosbagTimestamp,data
1438293888221082923,anticipation
1438293894686284247,start
1438293912206205027,reset
1438293951208942248,reset
1438293971527805563,reset

我得到了同样的错误。

1 个答案:

答案 0 :(得分:3)

这似乎有用

public partial class MainWindow : Window
{
    PieCollection pieCollection1;

    public MainWindow()
    {
        InitializeComponent();

        pieCollection1 = new PieCollection();

        pieCollection1.Add(new PiePoint { Name = "Mango", Share = 10 });
        pieCollection1.Add(new PiePoint { Name = "Banana", Share = 36 });
        pieCollection1.Add(new PiePoint { Name = "Grapes", Share = 15 });
        pieCollection1.Add(new PiePoint { Name = "Apple", Share = 20 });

        Chart1.DataContext = pieCollection1;
    }
}

enter image description here