我试图使标题不言自明,但这里 - 数据优先:
dtf <- structure(list(variable = structure(c(1L, 1L, 2L, 2L, 3L, 3L,
4L, 4L, 5L, 5L), .Label = c("vma", "vla", "ia", "fma", "fla"), class = "factor"),
ustanova = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L), .Label = c("srednja škola", "fakultet"), class = "factor"),
`(all)` = c(42.9542857142857, 38.7803203661327, 37.8996138996139,
33.7672811059908, 29.591439688716, 26.1890660592255, 27.9557692307692,
23.9426605504587, 33.2200772200772, 26.9493087557604)), .Names = c("variable",
"ustanova", "(all)"), row.names = c(NA, 10L), class = c("cast_df",
"data.frame"), idvars = c("variable", "ustanova"), rdimnames = list(
structure(list(variable …Run Code Online (Sandbox Code Playgroud) 我经常有刻面的数值.我希望提供足够的信息来解释补充标题中的这些分面值,类似于轴标题.贴标签选项重复了许多不必要的文本,并且对于较长的变量标题不可用.
有什么建议?
默认值:
test<-data.frame(x=1:20, y=21:40, facet.a=rep(c(1,2),10), facet.b=rep(c(1,2), each=20))
qplot(data=test, x=x, y=y, facets=facet.b~facet.a)
Run Code Online (Sandbox Code Playgroud)

我想要的是:

我能在ggplot中做得最好:
qplot(data=test, x=x, y=y)+facet_grid(facet.b~facet.a, labeller=label_both)
Run Code Online (Sandbox Code Playgroud)

如@Hendy所示,类似于: 在ggplot2图中添加辅助y轴 - 使其完美
我有一个简单的数据框,我正在尝试使用组合线和点图ggplot2.假设我的数据如下所示:
df <- data.frame(x=rep(1:10,2), y=c(1:10,11:20),
group=c(rep("a",10),rep("b",10)))
Run Code Online (Sandbox Code Playgroud)
而我正试图制作一个情节:
g <- ggplot(df, aes(x=x, y=y, group=group))
g <- g + geom_line(aes(colour=group))
g <- g + geom_point(aes(colour=group, alpha = .8))
g
Run Code Online (Sandbox Code Playgroud)
结果看起来很好,有一个例外.它有一个额外的图例显示alpha我的geom_point图层.

如何保持图例显示组颜色,但不能显示我的alpha设置?
library(ggplot2)
df <- data.frame(x=1:10, y=rnorm(10))
p1 <- ggplot(df, aes(x,y)) + geom_point()
plist <- list(p1,p1,p1,p1,p1)
# In my real example,a plot function will fit a ggplot to a list of datasets
#and return a list of ggplots like the example above.
Run Code Online (Sandbox Code Playgroud)
我想使用安排地块grid.arrange()在gridExtra.
如果图中的数量plist是可变的,我该怎么做?
这有效:
grid.arrange(plist[[1]],plist[[2]],plist[[3]],plist[[4]],plist[[5]])
但我需要一个更通用的解决方案.想法?
在尝试修改主题设置时,这个简单的代码会出现以下错误:
library(ggplot2)
theme_nogrid <- theme_set(theme_update(
plot.margin=unit(c(.25, .25, .25, .25), "in"),))
Error in do.call(theme, list(...)) : could not find function "unit"
Run Code Online (Sandbox Code Playgroud)
R给了我使用'unit'的任何元素的这个错误.任何其他不称为"单位"的设置都可以正常工作.我正在运行R v.2.15.2(64位Windows).
我在网上广泛搜索了这个问题,一无所获.我感谢对此问题的任何建议.
我正在使用ggplot2来改善降水条件.
这是我想要实现的可重现的例子:
library(ggplot2)
library(gridExtra)
secu <- seq(1, 16, by=2)
melt.d <- data.frame(y=secu, x=LETTERS[1:8])
m <- ggplot(melt.d, aes(x=x, y=y)) +
geom_bar(fill="darkblue") +
labs(x="Weather stations", y="Accumulated Rainfall [mm]") +
opts(axis.text.x=theme_text(angle=-45, hjust=0, vjust=1),
title=expression("Rainfall"), plot.margin = unit(c(1.5, 1, 1, 1), "cm"),
plot.title = theme_text(size = 25, face = "bold", colour = "black", vjust = 5))
z <- arrangeGrob(m, sub = textGrob("Location", x = 0, hjust = -3.5, vjust = -33, gp = gpar(fontsize = 18, col = "gray40"))) #Or guessing x and y …Run Code Online (Sandbox Code Playgroud) 我正在试图找出如何使用downloadButton来保存有光泽的情节.包中的示例演示了downloadButton/downloadHandler以保存.csv.我将基于此制作一个可重现的示例.
对于 ui.R
shinyUI(pageWithSidebar(
headerPanel('Downloading Data'),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
downloadButton('downloadData', 'Download Data'),
downloadButton('downloadPlot', 'Download Plot')
),
mainPanel(
plotOutput('plot')
)
))
Run Code Online (Sandbox Code Playgroud)
对于 server.R
library(ggplot2)
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
plotInput <- reactive({
df <- datasetInput()
p <-ggplot(df, aes_string(x=names(df)[1], y=names(df)[2])) +
geom_point()
})
output$plot <- renderPlot({
print(plotInput())
})
output$downloadData <- downloadHandler(
filename = function() { paste(input$dataset, '.csv', sep='') },
content = function(file) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试调整绘图以适应我的文档,但是我很难将绘制的图表做成正方形.
例:
pdf(file = "./out.pdf", width = 5, height = 5)
p <- ggplot(mydata, aes(x = col1, y = col2))
print(p)
aux <- dev.off()
Run Code Online (Sandbox Code Playgroud)
虽然x和y的限制是相同的,但结果中的图不是方形的.我猜R使封闭面板5x5"但不关心实际的图表大小.
我怎样才能解开图表?
我的例子是:
qplot(mtcars$mpg) + annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")
Run Code Online (Sandbox Code Playgroud)
如何让这里的文字保持对齐?所以'有些人相互排队.
当我试图生成一个情节时,我收到了这个警告ggplot.
在线研究了一段时间之后,许多人建议我的数据库包含空值或一般缺少数据,但事实并非如此.
在这个问题中,接受的答案如下:
警告意味着某些元素因为超出指定范围而被删除
我想知道这个范围究竟是指什么,以及如何有人手动增加这个范围以避免所有警告?