Set x-axis to be at y=0 ggplot2
I am trying to get my plot's x-axis to stay at y=0 despite the y-axis limits being set to -0.50, 0.50. I can't seem to figure out a way to draw the axis myself while still using ggplot2...
See sample code here:
c_sdata <- summarySE(fa_data, measurevar = "cbias", groupvars = c("AGE", "Image_Type")) # Use Image_Type as a factor as well as AGE c_sdata$AGE <- factor(c_sdata$AGE, levels = c("2","1")) c_sdata$Image_Type <- factor(c_sdata$Image_Type) # Error bars SEM ggplot(c_sdata, aes(x=Image_Type, y=cbias, fill=AGE)) + geom_bar(width=0.5, position=position_dodge(.6), stat="identity") + geom_errorbar(aes(ymin=cbias-se, ymax=cbias+se), width=.1, position=position_dodge(.6)) + xlab("Stimulus Type") + ylab("Response Bias") + scale_fill_manual(breaks = c("2","1"), name = "", labels=c("Older Adults", "Younger Adults"), values = c("grey57", "grey75")) + scale_x_discrete(limits = c("Upright_Faces", "Inverted_Faces", "Chairs", "Houses"), labels = c("Upright Faces", "Inverted Faces", "Chairs", "Houses"), position = "top") + theme_classic() + theme(legend.position = c(.25,.1), legend.direction = "horizontal", legend.key.size = unit(12, "points"))
Here is the output graph:
What I want is the x-axis to be at y = 0.
See also questions close to this topic
Extracting full article text via the newsanchor package [in R]
I am using the newsanchor package in R to try to extract entire article content via NewsAPI. For now I have done the following :
require(newsanchor) results <- get_everything(query = "Trump +Trade", language = "en") test <- results$results_df
This give me a dataframe full of info of (maximum) a 100 articles. These however do not containt the entire actual article text. Rather they containt something like the following:
 "Tensions between China and the U.S. ratcheted up several notches over the weekend as Washington sent a warship into the disputed waters of the South China Sea. Meanwhile, Google dealt Huaweis smartphone business a crippling blow and an escalating trade war co… [+5173 chars]"
Is there a way to extract the remaining 5173 chars. I have tried to read the documentation but I am not really sure.
Access both tails of the normal CDF in a single call of pnorm
I'm writing an R package in which I need to evaluate multiple times the (log of the) normal CDF
Phi(.)for each entries of a very large matrix
A(e.g., 5000 x 20000), and do this accurately for both tails, i.e.,
So far, I have been using the R function
logphiA <- pnorm(A, log.p = TRUE) log1_phiA <- pnorm(A, log.p = TRUE, lower.tail = FALSE)
which is quite expensive. Note that I can't use the cheaper and less accurate version for
log1_phiA <- log(1-exp(logphiA))
as this causes stability issues in my case.
I've looked up the C++ implementation of
pnormand I saw that it calls a void function
pnorm_bothwhich can compute both tails at once and is used within the function
pnorm5, see e.g. here. So I was wondering whether this could be a cheaper option of me, provided I can call it within my R code. Do you know if this is an option? Or should I copy the C++ sources and modify the
Or else, would you have another idea for a faster evaluation of the normal CDF, without giving up computational accuracy?
Plot function of svm in R
I have constructed a model of svm on a dataset of Fraud transactions , but when I am trying to plot the model it is neither showing any error nor showing any plot. My code is -
>library(e1071) >attach(FraudTransData) >model2<- svm(FraudTransData$Fraud_Ind~., data= FraudTransData) >plot(model2, FraudTransData)
I used the same plot function on another dataset cats and it showed a successful plot. I am unable to understand where have I gone wrong.
How to fix ggplot2 time series barchart bars that are too wide?
I am plotting a time series bar chart with a measure for different categories. When I plot the time series bar chart, the width of the bars fills over many dates so that the neighbouring bars touch, even if they are a month apart, but this means that it is unclear which date that bar corresponds to. How do I change the code so that the bars only appear over the date in the underlying dataframe?
I have successfully plotted another time series bar chart with exactly the same ggplot code but different underlying data and so it is unclear to me why this is happening with this particular dataframe.
In this following example, I use a dataframe with only one category for simplicity in highlighting the issue:
data <- data.frame(a = c(as.Date("2019-05-30"), as.Date("2019-06-19")), b = c("FX FORWARD", "FX FORWARD"), c = c(29.2, 74.7)) colnames(data ) <- c("Expiration Date", "Security Type", "Exposure $M") plot <- ggplot(data , aes(x=`Expiration Date`, y=`Exposure $M`, fill=`Security Type`)) + geom_bar(stat="identity") + scale_x_date(labels = scales::date_format("%d-%b"), date_breaks = "3 day")
I expected the bars to appear only above the day in which they are stored in the dataframe and not as it is shown in the chart, i.e. $29.2 above 31st May 2019 only and not spreading from 23rd May to 8th June; same for the second data point. Can anyone advise how I may correct this in my code?
Thanks in advance for any help, I've tried looking all over for a solution.
a graph with two lines, separating into different graphs based on one column values
I have a dataframe in this format, but with several hundred more rows:
dfex = data.frame(dot = c('A', 'B', 'C', 'D', 'E', 'F'), group = c('A1', 'A1', 'A1', 'A2', 'A2', 'A2'), x1 = c(1, 2, 3, 4, 5, 6), x2 = c(4, 5, 6, 1, 2, 3), y = c(1, 2, 3, 4, 5, 6))
I want to create different graphs based on the value in
group, so one graph will only have group A1 rows and the other graph only has group A2 rows.
On each graph, there should be two different lines for the x1-y pair and the x2-y pair. Preferably I could have the correlation for each of these lines listed as well.
I'm familiar with ggplot2, so using that would be great.
How can I change the type of significance bar on ggplot?
I have a ggplot that displays significance with downward brackets, but my boss wants them to have tick marks going up and down (see image below). As well, my boss wants the "ns" to be capital. Is there a good way to control this without having to it manually? I am making 10 plots total.
p <- ggplot(LessCountS, aes(x=Type, y=DC)) + geom_dotplot(aes(fill= Type), binwidth = 4.5, binaxis = "y", stackdir = "center", color = "black" ) + theme_gray ()+ labs(x="", y = "Cell Count (cells/uL")+ ggtitle("Dendritic cells") + scale_x_discrete(labels=c("HC" = "Controls", "IN" = "Inpatients", "OUT" = "Outpatients")) + theme(plot.title = element_text(hjust = 0.5, size = 14), legend.text=element_text(size=12), legend.position = "none", text = element_text(family = "Calibri"), axis.text = element_text(size=14), axis.title = element_text(size = 14)) + #scale_fill_brewer(palette="Purples") + scale_fill_manual(values=c("#CCCCCC", "#990066", "#3366CC")) + stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median, geom = "crossbar", width = 0.35) + stat_compare_means(comparisons = my_comparisons, label.y = , label = "p.signif", size = 5) p
Notice the difference in the significance denotations, I wan to make the dendritic plot look like the neutrophil plot.
Thanks in advance, S
Shift all plotted values along one of axes after Python plot is already called
Suppose I already called
ax.plot([10, 20, 30], some_y_values)
Do I understand right that it is impossible at this point to make all
xvalues less by e.g.
[0, 10, 20]? If I understand right
xlimwill not help here, as it changes limits of the graph, rather than values themselves.
ggplot manipulate axis margins
I have a bar plot of categorical variables. I'm trying to make the labels for the axis flush with the axis; essentially, justify the base of the bars to the labels. Any help would be appreciated.
Here's the code for the graph.
travel_deaths %>% filter(Type %in% commuting, data_type == "Journeys") %>% #filter out the stupid air travels mutate(rank = rank(.$deaths)) %>% ggplot(aes(x = reorder(Type, rank, order = TRUE), y = deaths, fill = factor(rank))) + geom_bar(stat="identity", show.legend = FALSE) + geom_text(aes(label = deaths), nudge_y = 40) + ggtitle("Deaths per Billion Trips") + scale_fill_manual(values = bloody(9)) + theme(axis.text.y = element_text(hjust = 1), axis.ticks.y = element_blank()) + coord_flip()
Currently it looks like this
This is what I am hoping to achieve
Efficient way to display a heatmap-like visualization with an object containing two names corresponding to X and Y axis
I can't figure out a proper way to display a two-dimensional grid of objects with points on either axis in common.
I'm working with Javafx in IntelliJ with Gradle. I'm working with medicine interactions and trying to show all possible medicine interactions in a patient's medicine list.
The idea is using a heatmap-like system to give a clinician a quick overview. Here's an example: https://i.imgur.com/BSrWAk8.png
All circles will be invisible if no interaction present. They'll change color depending between yellow/red depending on severity. The axis will only show for the medicines present in the patient's medicine list, starting from bottom left and fan out. E.g., if only five medicines with one interaction, there'll be five medicine names fanning out from bottom left and one circle, let's say on coordinate 2,1 between epinephrine and panodil.
I have two objects: 1) A medicine class with a name for each medicine, which is stored in a list. 2) An "interaction" class for each interaction present, which will be the circles. It contains two strings, one for the name of each of the two conflicting medicines. It also contains a severity.
I can't figure out a proper way to get this displayed from my objects and down on the view. I thought of possibly making a list for each column and somehow iterating through a list of all interactions and make an "if med A AND med B are also in axis, put circle there", but I imagine there's a better way.