Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (58 sloc) 2.346 kb
f89540f @hadley Use roxygen for documentation
authored
1 #' Visualise profiling data with base graphics.
2 #' Visualise profiling data stored in a \code{profr} data.frame.
3 #'
4 #' If you only want a small part of the total call tree, you will need
5 #' to subset the object as demonstrated by the example.
6 #'
7 #' @param x profile output to plot
8 #' @param ... other arguments passed on to \code{\link{plot.default}}
9 #' @param minlabel minimum percent of time for function to get a label
10 #' @param angle function label angle
11 #' @keywords hplot
12 #' @seealso \code{\link{ggplot.profr}}
75483a0 @hadley Add explicit NAMESPACING
authored
13 #' @method plot profr
14 #' @S3method plot profr
f89540f @hadley Use roxygen for documentation
authored
15 #' @examples
16 #' plot(nesting_prof)
17 #' plot(reshape_prof)
8345025 @hadley Improving documentation. Fixing a few small bugs
authored
18 plot.profr <- function(x, ..., minlabel = 0.1, angle = 0) {
a369b6a @hadley Convert tabs to spaces
authored
19 plot(1,1, xlim=range(x$start, x$end), ylim=range(x$level)+c(-0.5, 0.5), type="n", ..., xlab="time", ylab="level")
20 rect(x$start, x$level - 0.5, x$end, x$level +0.5, ...)
21 labels <- subset(x, time > max(time) * minlabel)
22 if (nrow(labels) > 0)
23 text(labels$start, labels$level, labels$f, pos=4, srt=angle, ...)
0719f4f @hadley Add ggplot plotting method
authored
24 }
25
f89540f @hadley Use roxygen for documentation
authored
26 #' Visualise profiling data with ggplot2.
27 #' Visualise profiling data stored in a \code{profr} data.frame.
28 #'
29 #' This will plot the call tree of the specified stop watch object.
30 #' If you only want a small part, you will need to subset the object
31 #'
32 #' @param data profile output to plot
33 #' @param ... other arguments passed on to \code{\link[ggplot2]{ggplot}}
34 #' @param minlabel minimum percent of time for function to get a label
35 #' @param angle function label angle
36 #' @seealso \code{\link{plot.profr}}
37 #' @keywords hplot
75483a0 @hadley Add explicit NAMESPACING
authored
38 #' @method ggplot profr
7e4b718 @hadley Fix imports and update docs
authored
39 #' @export
f89540f @hadley Use roxygen for documentation
authored
40 #' @examples
41 #' if (require("ggplot2", quiet = TRUE)) {
7e4b718 @hadley Fix imports and update docs
authored
42 #' ggplot(nesting_prof)
43 #' ggplot(reshape_prof)
f89540f @hadley Use roxygen for documentation
authored
44 #' }
8345025 @hadley Improving documentation. Fixing a few small bugs
authored
45 ggplot.profr <- function(data, ..., minlabel = 0.1, angle=0) {
4fb6c74 @hadley Formatting
authored
46 if (!require("ggplot2", quiet=TRUE))
47 stop("Please install ggplot2 to use this plotting method")
8345025 @hadley Improving documentation. Fixing a few small bugs
authored
48 data$range <- diff(range(data$time))
0719f4f @hadley Add ggplot plotting method
authored
49
50 ggplot(as.data.frame(data), aes(x = factor(level))) +
4fb6c74 @hadley Formatting
authored
51 geom_bar(aes(min = start, y = end),
52 position = "identity", stat = "identity",
53 width = 1, fill = "grey95", colour = "black", size = 0.5) +
54 geom_text(aes(label = f, y = start + range/60),
55 data = subset(data, time > max(time) * minlabel),
56 size = 4, angle = angle, hjust = 0) +
57 scale_y_continuous("time") +
58 scale_x_discrete("level") +
59 coord_flip()
60 }
Something went wrong with that request. Please try again.