2016-06-29 3 views
0

ggvisまたはggplot2にカラーバーを作成する方法を知っている人はいませんか?これをshinyアプリケーションに入れているので、ggvisが好ましい。 余裕のないggvis colorbar(またはggplot2)

私はggplot2で部分的に作業例を持っています。

データ:

legendData <- c(100, 325, 550, 775, 1000) 
legendColors <- c("#FF9DEB", "#9FC5FF", "#00E4D0", "#AAD44D", "#FFAE85") 
df <- data.frame(x = legendData, col = legendColors, y = 1:5, stringsAsFactors = FALSE) 

theme_nothing()ggmapから来て、あなたがhereから機能をコピーすることができます。

ggplot2(マージンを持っている):

ggplot(df, aes(y = 1, x = x, fill = col)) + geom_tile() + 
scale_fill_identity() + theme_nothing() 

これを実行するには、私にこのimageを与えます。残念ながら、これにはまだマージンがあります。

コードはggvisですが、もう機能しません。それは私に「スケールはすべて可算でなければならない、または可算ではない」というエラーを与えます。 (動作しない)

ggvis:

df %>% ggvis(~y, ~x, fill := ~col) %>% 
layer_rects(width = band(), height = band()) %>% 
scale_nominal("x", padding = 0, points = FALSE) %>% 
scale_nominal("y", padding = 0, points = FALSE) %>% 
add_axis("y", title = "", properties = axis_props(labels = list(fontSize = 14))) %>% 
add_axis("x", title = "") %>% set_options(width = 25, height = 100) 

感謝。 aosmith

+1

あなた' ggvis'コードが実行されます。 – aosmith

答えて

0

おかげで、これは動作します:あなたの代わりに整数の 'X'と `y`要因/文字を使用する場合

legendData <- as.factor(c(100, 325, 550, 775, 1000)) 
legendColors <- c("#FF9DEB", "#9FC5FF", "#00E4D0", "#AAD44D", "#FFAE85") 
df <- data.frame(x = legendData, col = legendColors, 
    y = as.factor(rep(1,length(legendData))), stringsAsFactors = FALSE) 
df %>% ggvis(~x, ~y, fill := ~col, strokeWidth := 0) %>% 
layer_rects(width = band(), height = band()) %>% hide_axis("x") %>% hide_axis("y") %>% 
scale_nominal("x", padding = 0, points = FALSE) %>% 
scale_nominal("y", padding = 0, points = FALSE) 
関連する問題