How to rotate a ggplot2 dendrogram?

Suppose I have a ggplot2 dendrogram like this:

require(ggplot2)
require(ggdendro)

hc <- hclust(dist(USArrests), "ave")
dhc <- as.dendrogram(hc)

ddata <- dendro_data(dhc, type="rectangle")

ggplot(segment(ddata),labels=rownames(USArrests))+ 
geom_segment(aes(x=x, y=y, xend=xend, yend=yend))+ 
theme_dendro()

How can I rotate it clockwisely in 90 degree? I found a few topics in coord_flip(), but I just want to rotate rather flip. I tried geom_segment(aes(x=y, y=x, xend=yend, yend=xend)), but it does not work. Here is the plot that I want to:

Answers


Use x and xend for y values and then y and yend for y values. With scale_y_reverse() you will get reversed order clusters.

ggplot(segment(ddata),labels=rownames(USArrests))+ 
  geom_segment(aes(y=x, x=y, yend=xend, xend=yend))+ 
  theme_dendro()+scale_y_reverse()

The same can be achieved using original code but adding coord_flip() to rotate by 90 degree and then add scale_x_reverse() to get reversed order.

ggplot(segment(ddata),labels=rownames(USArrests))+ 
  geom_segment(aes(x=x, y=y, xend=xend, yend=yend))+ 
  theme_dendro()+coord_flip()+scale_x_reverse()

Need Your Help

Select a div based one div class with a child div containing a certain id

jquery twitter-bootstrap jquery-selectors

I'm doing my own form validation thing for jQuery and I needed to target a specific div based on its child div's id. This is Bootstrap forms structure by the way. So given the following structure:

Regex for allowing numbers without leading and ending 0

regex

I want except some numbers in different syntax and I am trying to find the best Regex for this task/match.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.