ggplot2

ggplot2: blurry facet labels

旧时模样 提交于 2021-02-19 02:34:13
问题 When I save a ggplot figure -- regardless of whether I use ggsave() or e.g. png() -- the facet labels come out looking blurry. For example, the following code produces a facet label 'F' that looks like the picture below, with coloration on the outer pixels of the text raster. ggplot(data.frame(x=1, y=1, f='F'), aes(x, y)) + facet_grid(. ~ f) ggsave('foo.png') Thanks in advance for any advice! PS -- As per @Brian's request, I'm updating this post to note that I'm using a Windows machine. PPS -

how to replace legend 'bullet' of geom_text guide (legend)

廉价感情. 提交于 2021-02-19 01:28:50
问题 I would like to replace the 'bullets' in legend (guide) of geom_text . Now it's a tilted a , but I would like a big fat circle or a square or any other shape that will emphasize the color (more). library(ggplot2) majdf <- data.frame(lvl = rep(c("A", "B"), each = 50), val = c(rnorm(50, 1), rnorm(50, 3))) majtxt <- data.frame(species = c("sp1", "sp2", "sp3"), geq = c(0.01, 2, 2.2)) ggplot(majdf, aes(x = val)) + geom_density() + geom_vline(data = majtxt, aes(xintercept = geq)) + geom_text(data =

Produce multiple ggplot figures within one ggplot()

有些话、适合烂在心里 提交于 2021-02-19 01:27:53
问题 I would like to use the same ggplot code to produce 8 different figures conditional upon figures in my dataframe. Usually I would use facet_grid, but in this case, I would like to end up with a pdf of each individual figure. For example, I would like one pdf for each row here: df <- read.table(text = " xvalue yvalue location planting crop 1 5 A early corn 2 3 A late corn 6 2 A early soy 7 4 A late soy 4 7 S early corn 2 6 S late corn 3 2 S early soy 5 1 S late soy ", sep = "", header = TRUE)

Add “title” to my factors using facet_grid

家住魔仙堡 提交于 2021-02-19 01:25:09
问题 I would like to add text / title for my factors using ggplot2. For exemple for data from {reshape2} library: library(reshape2) library(ggplot2) ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1) + facet_grid(sex ~ .) Factors labels are: Female and Male. How can I add above them the title "sex"? 回答1: Adapting this answer. Slightly better version. Work out its own width. library(reshape2) library(ggplot2) library(grid) library(gtable) p = ggplot(tips, aes(x=total_bill, y

Plotting a regression line through the origin

这一生的挚爱 提交于 2021-02-18 21:13:04
问题 I am plotting some data series along with regression lines using this code: ggplot(dt1.melt, aes(x=lower, y=value, group=variable, colour=variable)) + geom_point(shape=1) + geom_smooth(method=lm, se=FALSE) However, I need to constrain the regression line to be through the origin for all series - in the same way as abline(lm(Q75~-1+lower,data=dt1)) would achieve on a standard R plot. Can anyone explain how to do this in ggplot ? 回答1: You need to specify this in the formula argument to geom

R - reformat P value in ggplot using 'stat_compare_means'

流过昼夜 提交于 2021-02-18 19:00:28
问题 I want to plot the p values to each panel in a faceted ggplot. If the p value is larger than 0.05, I want to display the p value as it is. If the p value is smaller than 0.05, I want to display the value in scientific notation (i.e, 0.0032 -> 3.20e-3; 0.0000425 -> 4.25e-5). The code I wrote to do this is: p1 <- ggplot(data = CD3, aes(location, value, color = factor(location), fill = factor(location))) + theme_bw(base_rect_size = 1) + geom_boxplot(alpha = 0.3, size = 1.5, show.legend = FALSE)

Error in Shiny deployment on shinyapps.io

可紊 提交于 2021-02-18 18:15:11
问题 I got a Shiny App that works fine on my PC, but once I deploy on shinyapps.io it shows the following error on the web browser: And the following error on the Deployment Console: Warning message: In value[[3L]](cond) : Failed to parse C:/Users/david.jorquera/AppData/Local/Temp/RtmpSOqdYV/file13849671673/app.R ; dependencies in this file will not be discovered. If you need the exact excel file I'm using I would happily attach it if you tell me how to do it (sorry, haven't figure that out yet).

add a second geom_tile layer in ggplot

▼魔方 西西 提交于 2021-02-18 18:14:10
问题 I have a relatively simple heatmap using geom_tile in ggplot2. It's just a small matrix of continuous data as colored boxes ( df1 ) and I'd like to overlay a second, logical geom_tile that outlines the TRUE values ( df2 ). Can such a thing be done? I know that adding two heatmaps together seems like it would be ugly but these are small and pretty simple affairs. library(ggplot2) n <- 4 df1 <- data.frame(x = rep(letters[1:n], times = n), y = rep(1:n, each = n), z = rnorm(n ^ 2)) df2 <- data

Plot a table of separate data below a ggplot2 graph that lines up on the X axis

自闭症网瘾萝莉.ら 提交于 2021-02-18 18:11:59
问题 I'm looking to create a plot that contains a simple multi-line ggplot2 graph with a table of separate (but relevant) data below the graph that lines up by the X axis of the graph. The data table's column names do match the x axis of the graph (hours 1 to 24), but one column is dedicated to necessary row names. Here are the graph and the data table separately: Data table is cut off at hour 16 for brevity, but does extend to 24. I've been attempting different solutions in gridExtra all morning

Plot a table of separate data below a ggplot2 graph that lines up on the X axis

孤人 提交于 2021-02-18 18:11:00
问题 I'm looking to create a plot that contains a simple multi-line ggplot2 graph with a table of separate (but relevant) data below the graph that lines up by the X axis of the graph. The data table's column names do match the x axis of the graph (hours 1 to 24), but one column is dedicated to necessary row names. Here are the graph and the data table separately: Data table is cut off at hour 16 for brevity, but does extend to 24. I've been attempting different solutions in gridExtra all morning