R: Stacked bar chart

时间:2018-12-19 11:35:24

标签: r data-visualization

I am trying to make a stacked bar chart with each mark in stacked bar corresponds to each row in the data. Each bar corresponds to one hour thus contains 60 marks for each minute. I think barplot function will be used but able to figure it out how? Also there's another column with some values. If there's value in that column I want that value in place of mark. Here's the data i am using

RowNo   State   Bar
  1        a    1
  2             1
  3             1
  .
  .
 59             1
 60             1
 61             2
 62             2
 .
 .
 1199           20
 1200           20
 1201      c    21

And this is what I am looking for enter image description here

Any Help would be appreciated.

1 个答案:

答案 0 :(得分:0)

与此类似:

#include <map>
#include <string>

class Singleton {
private:
    std::map<std::string, std::string> m_map;
    bool m_locked;
    Singleton() : m_locked(false) { }

public:
    static Singleton& instance() {
        static Singleton theSingleton;
        return theSingleton;
    }

    static void lock() {
        instance().m_locked = true;
    }

    static bool insert(const std::string& key, const std::string& value) {
        if (instance().m_locked) { return false; }
        return instance().m_map.insert(std::make_pair(key, value)).second;
    }
    static std::string at(const std::string& key) {
        return instance().m_map.at(key);
    }
};

static bool inserted = Singleton::insert("Hello", "World"); // fine

bool addItem(const std::string& key, const std::string& value) {
    return Singleton::insert(key, value); // not OK
}

int main(int argc, char** argv)
{
    Singleton::lock();
    Singleton::insert("Hello2", "World2"); // fails
    return 0;
}

enter image description here