treemap

Converting treemap to ggplot

只谈情不闲聊 提交于 2019-11-28 10:23:48
问题 The good news: I'm able to create a beautiful treemap using the treemap package. Data: forTm <- structure(list( UnitGroup = c("1N", "BHU", "CSU", "ED", "Med/Surg", "Med/Surg", "Telemetry", "Telemetry", "Telemetry", "Telemetry", "Telemetry"), Unit = c("A", "B", "C", "ED", "D", "E", "F", "G", "H", "I", "J"), Count = c(1L, 1L, 1L, 1L, 15L, 10L, 5L, 2L, 3L, 8L, 4L)), class = c("data.frame"), row.names = c(NA, -11L), .Names = c("UnitGroup", "Unit", "Count")) Treemap: library(treemap) tm <- treemap

Java Sort a Guava TreeBasedTable

被刻印的时光 ゝ 提交于 2019-11-28 08:47:54
问题 I have a TreeBasedTable object from Guava (Gooogle Collections). It is in the form of TreeBasedTable<k1, k2, v> . k1 and k2 implement Comparable . Now when I display the table, I want the user to be able to sort it different ways to change the order of the values. The approach I tried was to iterate over the table, and for each value, change a variable that's used in the Compare method. The trouble is it gets through the loop once, and then returns a NullPointerException , which I think I've

How to remove and add elements to TreeMap while iterating?

烈酒焚心 提交于 2019-11-28 07:20:18
问题 I want to write code like this - for (Map.Entry<Long, Integer> e : map.entrySet()){ map.remove(k); map.put(x, value); } but I got java.util.ConcurrentModificationException I tried to use Iterator also but I got the same Exception 回答1: Explanation why it caused ConcurrentModificationException map.remove(k); map.put(x, value); for-each loop also internally create a iterator of the entrySet of map . While iterating over map you have modified the structure of the map by putting the value again to

How to iterate over a TreeMap? [duplicate]

▼魔方 西西 提交于 2019-11-28 02:52:04
Possible Duplicate: How do I iterate over each Entry in a Map? I want to iterate over a TreeMap , and for all keys which have a particular value, I want them to be added to a new TreeMap . How can I do this? Assuming type TreeMap<String,Integer> : for(Map.Entry<String,Integer> entry : treeMap.entrySet()) { String key = entry.getKey(); Integer value = entry.getValue(); System.out.println(key + " => " + value); } (key and Value types can be any class of course) karim79 //create TreeMap instance TreeMap treeMap = new TreeMap(); //add key value pairs to TreeMap treeMap.put("1","One"); treeMap.put(

How to plot grid plots on a same page?

别来无恙 提交于 2019-11-28 01:55:55
问题 I am using a package ( treemap ) that uses grid package to produce a treemap. However, I would like to plot several of these treemaps together, to add different color schemes to these plots. tmPlot function uses grid.newpage function, which clears the graphics window. I have not found a way to save grid.newpage objects as you can do for ggplot2 objects. Is there a way to plot several grid.newpage objects to a same window? ## Example library(treemap) # load Gross national income data data

Create a SortedMap in Java with a custom Comparator

笑着哭i 提交于 2019-11-27 23:30:17
I want to create a TreeMap in Java with a custom sort order. The sorted keys which are string need to be sorted according to the second character. The values are also string. Sample map: Za,FOO Ab,Bar polygenelubricants You can use a custom comparator like this: Comparator<String> secondCharComparator = new Comparator<String>() { @Override public int compare(String s1, String s2) { return s1.substring(1, 2).compareTo(s2.substring(1, 2)); } }; Sample: SortedMap<String,String> map = new TreeMap<String,String>(secondCharComparator); map.put("Za", "FOO"); map.put("Ab", "BAR"); map.put("00", "ZERO"

Gradient color in a treemap for D3

隐身守侯 提交于 2019-11-27 22:49:59
问题 First of all this is different from the previous question asked in the posts, for what i am trying to achieve is a gradient for the entire treemap in d3, like what we have in google treemaps. I am trying to implement http://bost.ocks.org/mike/treemap/ and working on the same, but in d3 i was trying to have a color gradient in it. Currently I am doing this by color = d3.scale.category20c() and .style("fill", function(d) { return color(d.name)}) on my svg element. But i want to have a gradiant

Java: SortedMap, TreeMap, Comparable? How to use?

こ雲淡風輕ζ 提交于 2019-11-27 22:33:22
I have a list of objects I need to sort according to properties of one of their fields. I've heard that SortedMap and Comparators are the best way to do this. Do I implement Comparable with the class I'm sorting, or do I create a new class? How do I instantiate the SortedMap and pass in the Comparator? How does the sorting work? Will it automatically sort everything as new objects are inserted? EDIT: This code is giving me an error: private TreeMap<Ktr> collection = new TreeMap<Ktr>(); (Ktr implements Comparator<Ktr> ). Eclipse says it is expecting something like TreeMap<K, V> , so the number

Selecting random key and value sets from a Map in Java

 ̄綄美尐妖づ 提交于 2019-11-27 20:25:28
I want to get random keys and their respective values from a Map. The idea is that a random generator would pick a key and display that value. The tricky part is that both key and value will be strings, for example myMap.put("Geddy", "Lee") . HashMap<String, String> x; Random random = new Random(); List<String> keys = new ArrayList<String>(x.keySet()); String randomKey = keys.get( random.nextInt(keys.size()) ); String value = x.get(randomKey); Narendra Yadala This question should be of help to you Is there a way to get the value of a HashMap randomly in Java? and this one also Picking a random

d3.nest() key and values conversion to name and children

有些话、适合烂在心里 提交于 2019-11-27 19:52:28
I am working on creating a Treemap from a csv file. The data in the csv file is hierarchical, as a result I used d3.nest() . However, the resulting JSON is in the form of {key:"United States", values:[...]} . The zoom-able treemap requires hierarchy as {name:"United States", children:[...]} . I have tried replacing name and children to key and values in the example, but it doesn't work. If anyone has already looked into using key and values on a zoomable treemap, please help. I am new to D3 and I don't know whether d.children means structure or value from the data. This is the code to convert