I think the answer is no. Consider the following subsets of the Euclidean plane. 

Let $X_0 = \{(p,q)\in (\mathbb R\setminus \mathbb Q)\times \mathbb R: 
 0\le p \le 1, 0 \le q \le 1 \}$, $X_1 = \{(p,q)\in (  \mathbb Q)\times \mathbb R: 
 0\le p \le 1, -1  \le q \le 0 \}$, 

Let  $X=X_0\cup X_1$, $Y=[0,1]$, and let $f$ be the projection.